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

Discussion in 'Ruby' started by Rie!, Mar 26, 2008.

  1. Rie!

    Rie! Guest

    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.com/2bjgvn,
    ruby: http://www.ruby-lang.org/id/about

    I always thought Smalltalk would beat Java, I just didn't know it
    would be called 'Ruby' when it did. -- Kent Beck.
    Rie!, Mar 26, 2008
    #1
    1. Advertising

  2. Rie!

    Peña, Botp Guest

    From: Rie! [mailto:]=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
    Peña, Botp, Mar 26, 2008
    #2
    1. Advertising

  3. Rie!

    Rie! Guest

    On 26/03/2008, Pe=F1a, Botp <> 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.com/2bjgvn,
    ruby: http://www.ruby-lang.org/id/about

    I always thought Smalltalk would beat Java, I just didn't know it
    would be called 'Ruby' when it did. -- Kent Beck.
    Rie!, Mar 26, 2008
    #3
  4. Rie!

    Guest

    > On 26/03/2008, Peña, Botp <> 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
    , Mar 26, 2008
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Siemel Naran

    Does true ^ true return false?

    Siemel Naran, Jun 17, 2004, in forum: C++
    Replies:
    19
    Views:
    654
    Chris Theis
    Jun 18, 2004
  2. Jeremy Bowers
    Replies:
    3
    Views:
    504
    Steven Bethard
    Jan 24, 2005
  3. Mr. SweatyFinger

    why why why why why

    Mr. SweatyFinger, Nov 28, 2006, in forum: ASP .Net
    Replies:
    4
    Views:
    863
    Mark Rae
    Dec 21, 2006
  4. Mr. SweatyFinger
    Replies:
    2
    Views:
    1,766
    Smokey Grindel
    Dec 2, 2006
  5. bdb112
    Replies:
    45
    Views:
    1,321
    jazbees
    Apr 29, 2009
Loading...

Share This Page