[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

private class methods- functionality or shortcoming?

amit saxena

6/10/2008 8:11:00 AM

"> The Module#private method only works for instance methods,
> not for class
> method."

My question is, why is it so? What's the advantage in it?

Amit


--- On Mon, 6/9/08, Stefano Crocco <stefano.crocco@alice.it> wrote:

> From: Stefano Crocco <stefano.crocco@alice.it>
> Subject: Re: private class methods- functionality or shortcoming?
> To: "ruby-talk ML" <ruby-talk@ruby-lang.org>
> Date: Monday, June 9, 2008, 7:39 PM
> On Monday 09 June 2008, amit saxena wrote:
> > I just switched to Ruby and came across it.
> > If we have to make a class method private then we
> should write it as:
> >
class Abc

class<<self
private
def fun
p "hello"
end
end

end

> >But if we write as:

class Abc

private
def self.fun
p "hello"
end

end


> >
> > then the class method is not private but behaves as
> public.
> >
> > So, is it a carefully designed functionality? If so,
> then what is the
> > thinking behind it? OR any other reasons behind it?
> > Somebody told me that ruby encourages to define class
> methods the first
> > way. But I think that if you are giving more than one
> methods to do a
> > thing, then all should function the same way.
> >
> > Thanks and Regards,
> > Amit
>
> The Module#private method only works for instance methods,
> not for class
> method. To make a class method private, you should use the
> Module#private_class_method method. Note that, unlike
> private,
> private_class_method only accepts one argument, so that you
> want to make more
> than one method private, you should call it multiple times.
>
> So, the correct method to make the method private using the
> second form is:
>
> class Abc
>
> def self.fun
> p "hello"
> end
> private_class_method :fun
>
> end
>
> I hope this helps
>
> Stefano





2 Answers

RearGunner

11/15/2007 9:31:00 AM

0

In article <7cCdneMlNPoAQKbanZ2dnUVZ_hGdnZ2d@giganews.com>,
onlytetruth@alltimes.yo says...
> I'm an extremely honest and open minded person
>

liar!

B'enjamin C'ramer

11/15/2007 10:01:00 AM

0


"RearGunner" <RearGunner@Nospam.com> wrote in message
news:MPG.21a6bccb8f096a389896c2@west.usenet-news.net...
> In article <7cCdneMlNPoAQKbanZ2dnUVZ_hGdnZ2d@giganews.com>,
> onlytetruth@alltimes.yo says...
>> I'm an extremely honest and open minded person
>>
>
> liar!

I'm sorry to hear that.

You can get help, yanno. Give cohen a yell. She's taking aversion therapy
right now.