[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Singleton object vs. enhancing singleton class

Paul McMahon

6/9/2008 3:35:00 AM

In ruby, as class are singleton objects, does anyone have any ideas when
a a singleton object should be used vs. simply adding methods to the
class? For example,

class Foo
include Singleton
def bar
end
end

vs.

class Foo
def self.bar
end
end

9 Answers

David Masover

6/9/2008 4:03:00 AM

0

On Sunday 08 June 2008 22:35:25 Paul McMahon wrote:
> In ruby, as class are singleton objects, does anyone have any ideas when
> a a singleton object should be used vs. simply adding methods to the
> class?

I always include Singleton, but I see what you mean. A better way might be to
do it with modules:

module Foo
def self.bar
end
end

One example is mixins, though. For example, here:

> class Foo
> def self.bar
> end
> end

A mixin would almost certainly be expecting to be mixed via "include" here,
not "extend". This might not always matter, but some mixins will define
things like self.included, and won't work at all if you try to extend them
instead.

However, a mixin which expected "extend" would still work on a Singleton
object:

class Foo
include Singleton
def bar
end
end
Foo.instance.extend SomeMixin

I think the main reason for doing Singleton, though, is that it expresses
intent better, and it prevents the class from being instantiated -- sure,
there are ways around it, but you're not going to accidentally call Foo.new
without getting an error.

David Masover

6/9/2008 4:04:00 AM

0

In reply to myself:

> it prevents the class from being instantiated

To clarify -- prevents it from being instantiated again.

David A. Black

6/9/2008 6:05:00 AM

0

Hi --

On Mon, 9 Jun 2008, Paul McMahon wrote:

> In ruby, as class are singleton objects, does anyone have any ideas when

I'd just say: classes are objects. Like other objects, they can have
methods added to them on a per-object basis (give or take the fact
that "per-object" in the case of a class actually includes
subclasses).

> a a singleton object should be used vs. simply adding methods to the
> class? For example,
>
> class Foo
> include Singleton
> def bar
> end
> end
>
> vs.
>
> class Foo
> def self.bar
> end
> end

I don't see these techniques as addressing the same problem or being
likely candidates to replace each other. I'd go by what you need. If
you need a class that has only one instance, then use Singleton. If
you've got a situation where there's class-level (as opposed to
instance-level) knowledge involved, then use a class method.


David

--
Rails training from David A. Black and Ruby Power and Light:
INTRO TO RAILS June 9-12 Berlin
ADVANCING WITH RAILS June 16-19 Berlin
ADVANCING WITH RAILS July 21-24 Edison, NJ
See http://www.r... for details and updates!

Dirty Sick Pig

9/18/2008 10:33:00 PM

0

rst0wxyz wrote:
> On Sep 18, 10:35 am, Dirty Sick Pig <drtysicpig@pigs_lodge_1.org>
> wrote:
>> Siansiansian wrote:
>>> From tax payyer? But there are too many American will be out of job,
>>> the tax $ collected will be much lesser in the past.
>> Bullshit. We collected so much in taxes that we got back rebates. I
>> used mine to buy tools and downpayment for a new car. How about you?
>> Ever got a tax rebate in your miserable life?
>
> Yes, spent it like you're supposed to.

That was the intent of the rebates, thank you, cur.

>>> Increase income tax rate? The polticians will be risking the voters
>>> votes, and life is going to be very tough, people will cut spending,
>>> and thus bring ecomomy into depper recession.
>> That's the Democratic Party's plan. It won't happen.
>>
>>> Printing more US$? The US $ will be devalued further, and how low can
>>> it goes?

As low as your self-imposed optimism, Old Man.

> > That is the speculation of the braindead. We don't fuck around with
>> our printing presses and that is why our dollar is still the world's
>> foremost currency. BWAHAHAHAHAHAHAHAWR! Can you spend Euros in Fiji?

>
> The Chinese and Japanese are printing boodles of oodles for you.

False. We have presses in the East Coast, Mid-America and the West
Coast. We have a small one that does extra-special, one-off documents
in Annapolis, Maryland, smack in the middle of the Naval Academy. We
don't need our negotiable instruments stamped "Made in the Orient." But
in case you're interested, the Thomas De La Rue Company in Great Britain
prints all kinds of crap and scrap for the Japanese and Chinese.
BWAHAHAHAHAHAHAHAHAWR!

>>> Inflation will increase the hardship for the jobless,
>> Our honest but unfortunate jobless have Unemployment Compensation. And
>> do you know what our jobless rate is, in percent? BWAHAHAHAHAHAWR!
>
> The last figure I heard was 7.1% unemployment rate.

That's bad?

> The unemployment insurance only pays for 6 months.

Enough time to find placement or start in business.

>>> and Govt may have to fork out more fund.
>> More where the money is and we were able to demonstrate that these past
>> few days. You seem to think the USA is poor like your miserable
>> country. BWAHAHAHAHAHAHAHAHAWR!
>>
>> Do you want to buy an old non-nuclear aircraft carrier just for the
>> metals? How about three carriers? BWAHAHAHAHAWR!
>
> Is it still good for scraps?

Mega-tons of marine grade steel, aluminum, copper, titanium, tin, brass,
you name it. Plus super-maintained marine engines built to military
specs. The propellers alone are worth a megafortune. Tons of wood and
plastics too. Each one is worth more than a mine. Two are still flying
commissioning pennants and Old Glory.

baldeagle

9/18/2008 10:38:00 PM

0

On Sep 19, 1:35 am, Dirty Sick Pig <drtysicpig@pigs_lodge_1.org>
wrote:
> Siansiansian wrote:

> > From tax payyer? But there are too many American will be out of job,
> > the tax $ collected will be much lesser in the past.
>
> Bullshit.  We collected so much in taxes that we got back rebates.
>

Look at the US budget.... the USA spend more than its revenue
collection.
That's that reason why it has to borrow money from China and
Japan to finance the war...no money from tax payer(budget).


The US national debt is now in trillions, and trillions. ..now
exactly
$ 9 , 6 4 8 , 9 9 3 , 0 5 3 , 1 7 0 . 2 7

it will be more 1.8 billion more by tomorrow. See website below:
http://www.brillig.com/d...




Dirty Sick Pig

9/18/2008 11:01:00 PM

0

baldeagle wrote:
> On Sep 19, 1:35 am, Dirty Sick Pig <drtysicpig@pigs_lodge_1.org>
> wrote:
>> Siansiansian wrote:
>
>>> From tax payyer? But there are too many American will be out of job,
>>> the tax $ collected will be much lesser in the past.
>> Bullshit. We collected so much in taxes that we got back rebates.
>>
>
> Look at the US budget.... the USA spend more than its revenue
> collection.

Hey, stupid! USA does not depend on revenue collections ALONE. Moron.

> That's that reason why it has to borrow money from China and
> Japan to finance the war...no money from tax payer(budget).

Hey, stupid! USA does not depend on revenue collections ALONE. Moron.

> The US national debt is now in trillions, and trillions. ..now
> exactly
> $ 9 , 6 4 8 , 9 9 3 , 0 5 3 , 1 7 0 . 2 7
>
> it will be more 1.8 billion more by tomorrow. See website below:
> http://www.brillig.com/d...

So? <SHRUG> And who has the better international credit and bond
rating? U.S. or China? BWAHAHAHAHAHAHAHAHAHAWR!

Stupid. Idiot. Moron. Imbecile. Town fool. Baldostritch.

baldeagle

9/18/2008 11:50:00 PM

0

On Sep 19, 7:00 am, Dirty Sick Pig <drtysicpig@pigs_lodge_1.org>
wrote:
> baldeagle wrote:
> > On Sep 19, 1:35 am, Dirty Sick Pig <drtysicpig@pigs_lodge_1.org>
> > wrote:
> >> Siansiansian wrote:
>
> >>> From tax payyer? But there are too many American will be out of job,
> >>> the tax $ collected will be much lesser in the past.
> >> Bullshit.  We collected so much in taxes that we got back rebates.
>
> > Look at the US budget.... the USA spend more than its revenue
> > collection.
>
> Hey, stupid!  USA does not depend on revenue collections ALONE.  Moron.
>
> > That's that reason why it has to borrow money from China and
> > Japan to finance the war...no money from tax payer(budget).
>
> Hey, stupid!  USA does not depend on revenue collections ALONE.  


>
> > The US national debt is now in trillions, and trillions. ..now
> > exactly
> > $ 9 , 6 4 8 , 9 9 3 , 0 5 3 , 1 7 0 . 2 7
>
> > it will be more 1.8 billion more by tomorrow. See website below:
> >http://www.brillig.com/d...
>
> So?
 
The point,.. your claim that tax revenue was so much that
Bush pay back cash to American.
This is NOT accurate...untrue.
Bush made use from 'loan' to pay US taxpayer about $600 each
...the money was NOT from surplus from the budget.

The increase in national debts show how Bush got the money
to US tax payers.


> Stupid.  Idiot.  Moron.  Imbecile.  Town fool.  Baldostritch.

Dirty Sick Pig

9/19/2008 1:26:00 AM

0

baldeagle wrote:
> On Sep 19, 7:00 am, Dirty Sick Pig <drtysicpig@pigs_lodge_1.org>
> wrote:
>> baldeagle wrote:
>>> On Sep 19, 1:35 am, Dirty Sick Pig <drtysicpig@pigs_lodge_1.org>
>>> wrote:
>>>> Siansiansian wrote:
>>>>> From tax payyer? But there are too many American will be out of job,
>>>>> the tax $ collected will be much lesser in the past.
>>>> Bullshit. We collected so much in taxes that we got back rebates.
>>> Look at the US budget.... the USA spend more than its revenue
>>> collection.
>> Hey, stupid! USA does not depend on revenue collections ALONE. Moron.
>>
>>> That's that reason why it has to borrow money from China and
>>> Japan to finance the war...no money from tax payer(budget).
>> Hey, stupid! USA does not depend on revenue collections ALONE.
>
>>> The US national debt is now in trillions, and trillions. ..now
>>> exactly
>>> $ 9 , 6 4 8 , 9 9 3 , 0 5 3 , 1 7 0 . 2 7
>>> it will be more 1.8 billion more by tomorrow. See website below:
>>> http://www.brillig.com/d...
>> So? [shrug]
>
> The point,.. your claim that tax revenue was so much that
> Bush pay back cash to American.

STUPID! Taxes are just a part of REVENUE. There are other sources of
income for the USA, there are other forms of taxes. And I was talking
of INCOME TAX when I mentioned the rebates, but you are too STUPID to
make the distinction. STUPID!

> This is NOT accurate...untrue.

Hey, STUPID, I'll pay for a daily newspaper subscription for you. Your
choice. As a matter of fact, ask for more than one, stupid, because I
can afford it. Tell me which mental hospital to send it to. STUPID.

> Bush made use from 'loan' to pay US taxpayer about $600 each
> ..the money was NOT from surplus from the budget.

STUPID. You're guessing just to come up with a retort. STUPID.

> The increase in national debts show how Bush got the money
> to US tax payers.

STUPID. You don't have enough resources to read and understand the
Budget of the United States. The number of volumes alone will wreck
your hovel. And you will need a hundred assistants with more brains
than you do. STUPID.

Stupid. Idiot. Moron. Imbecile. Town fool. Baldostritch.

baldeagle

9/19/2008 8:14:00 AM

0

On Sep 19, 9:25 am, Dirty Sick Pig <drtysicpig@pigs_lodge_1.org>
wrote:

>
> STUPID!  Taxes are just a part of REVENUE.  There are other sources of
> income ...

Who is the stupid fool who previously said...
" We collected so much in TAXES that we got back rebates.."

Are you not talking about t a x e s ???

Sick babi is sick babi.

Ha ha ha ha