[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

Re: About class methods visibility (public/private

John Joyce

3/22/2007 2:49:00 PM

You mean you want Java or C++ or something else.
It's Ruby.
All methods are either public, protected or private.
It's a very simple system. It doesn't need further complication.

2 Answers

Gavin Kistner

3/22/2007 3:52:00 PM

0

From: Ruby Admirer [mailto:ruby_admirer@yahoo.com]
> Sent: Thursday, March 22, 2007 9:29 AM
> >John Joyce <dangerwillrobinsondanger@gmail.com> wrote:
>
> >You mean you want Java or C++ or something else.
> >It's Ruby.
>
> I don't really understand what you mean.
> Please, read again my post.
> I love Ruby (my pseudo is Ruby Admirer) and public_class_method and
> private_class_method are already parts of Ruby !

No, they're not:
C:\>irb
irb(main):001:0> Object.public_class_methods
NoMethodError: undefined method `public_class_methods' for
Object:Class
from (irb):1
irb(main):002:0> Object.private_class_methods
NoMethodError: undefined method `private_class_methods' for
Object:Class
from (irb):2

C:\>irb -v
irb 0.9.5(05/04/13)

C:\>ruby -v
ruby 1.8.5 (2006-08-25) [i386-mswin32]


Maybe you're thinking of some module or library in Ruby on Rails? (I
don't know if it includes those methods or not.)

> I completely agree. My first question was indeed why public, protected,
> private "statement" (they are in fact methods) does not work for class
> methods ?

'Class' methods, like 'class' instance variables, are no different
from normal methods and instance variables. They are just defined in a
different scope.

Gavin Kistner

3/22/2007 4:06:00 PM

0

On Mar 22, 9:51 am, "Phrogz" <g...@refinery.com> wrote:
> From: Ruby Admirer [mailto:ruby_admi...@yahoo.com]
>
> > Sent: Thursday, March 22, 2007 9:29 AM
> > >John Joyce <dangerwillrobinsondan...@gmail.com> wrote:
>
> > >You mean you want Java or C++ or something else.
> > >It's Ruby.
>
> > I don't really understand what you mean.
> > Please, read again my post.
> > I love Ruby (my pseudo is Ruby Admirer) and public_class_method and
> > private_class_method are already parts of Ruby !
>
> No, they're not:
> C:\>irb
> irb(main):001:0> Object.public_class_methods
> NoMethodError: undefined method `public_class_methods' for
> Object:Class
> from (irb):1
> irb(main):002:0> Object.private_class_methods
> NoMethodError: undefined method `private_class_methods' for
> Object:Class
> from (irb):2

My fault, I misread and thought I saw an extra 's' on the end there.
Of course Module#public_class_method is included in the core of Ruby.

Apologies for the noise.