[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

private(true) || private :make_time, what does it do? why?

Arie Kusuma Atmaja

3/26/2008 8:08:00 AM

i found that rake source has got this strange one line of code

private(true)

or something, true could be another code (I don't remember that rake
source code by heart). I'm not sure I can explain it clearly. Now I
just saw it again in time.rb file inside lib in ruby19 source code,
the code is like this

private :make_time

could anyone explain to me why this private takes an argument and what it does?

--
blog: http://tinyurl....,
ruby: http://www.ruby-lang.or...

I always thought Smalltalk would beat Java, I just didn't know it
would be called 'Ruby' when it did. -- Kent Beck.

3 Answers

Peña, Botp

3/26/2008 8:16:00 AM

0

From: Rie! [mailto:ariekusumaatmaja2@gmail.com]=20
# could anyone explain to me why this private takes an argument=20
# and what it does?

qri is your friend

botp@pc4all:~$ qri private
--------------------------------------------------------- Module#private
private =3D> self
private(symbol, ...) =3D> self
------------------------------------------------------------------------
With no arguments, sets the default visibility for subsequently
defined methods to private. With arguments, sets the named methods
to have private visibility.

module Mod
def a() end
def b() end
private
def c() end
private :a
end
Mod.private_instance_methods #=3D> ["a", "c"]


kind regards -botp

Arie Kusuma Atmaja

3/26/2008 11:40:00 AM

0

On 26/03/2008, Pe=F1a, Botp <botp@delmonte-phil.com> wrote:

> qri is your friend
>
> botp@pc4all:~$ qri private
> --------------------------------------------------------- Module#private
> private =3D> self
> private(symbol, ...) =3D> self
> ------------------------------------------------------------------------
> With no arguments, sets the default visibility for subsequently
> defined methods to private. With arguments, sets the named methods
> to have private visibility.
>
> module Mod
> def a() end
> def b() end
> private
> def c() end
> private :a
> end
> Mod.private_instance_methods #=3D> ["a", "c"]

if it's only about a method then it's trivial, what I meant was
something like this.

private(*somethingsomething)

anyone can explain it to me more clear?

m:lib arie$ rak "private\(" rake.rb
1091|private(*FileUtils.instance_methods(false))
1092|private(*RakeFileUtils.instance_methods(false))

oh wait, sorry for the noise, I know the answer! so private also
accepts an array of string values which are method names. Thanks for
the clue :-)

> kind regards -botp

--=20
blog: http://tinyurl....,
ruby: http://www.ruby-lang.or...

I always thought Smalltalk would beat Java, I just didn't know it
would be called 'Ruby' when it did. -- Kent Beck.

benjohn

3/26/2008 12:40:00 PM

0

> On 26/03/2008, Peña, Botp <botp@delmonte-phil.com> wrote:
> m:lib arie$ rak "private\(" rake.rb
> 1091|private(*FileUtils.instance_methods(false))
> 1092|private(*RakeFileUtils.instance_methods(false))
>
> oh wait, sorry for the noise, I know the answer! so private also
> accepts an array of string values which are method names. Thanks for
> the clue :-)

Slightly more precisely (and very pedantically), private _isn't_ accepting
an array in this case. The * is there to expand an array (which it doesn't
want) in to seperate arguments (which it likes).

Cheers,
B