Object#singleton_class in Ruby 1.9?

Discussion in 'Ruby' started by Suraj Kurapati, Jan 30, 2009.

  1. Hello,

    I was under the impresssion that Ruby 1.9 will provide
    Object#singleton_class (or #eigen_class or #meta_class), which would
    save us the trouble of writing "class << self; self; end" everywhere.

    But in Ruby 1.9.1-rc2, I do not see this:

    >> RUBY_DESCRIPTION

    => "ruby 1.9.1p0 (2009-01-20 revision 21700) [i686-linux]"

    >> Object.instance_methods.grep(/class|singleton|eigen|meta/)

    => [:class, :singleton_methods, :define_singleton_method]

    Was Object#singleton_class (or #eigen_class or #meta_class) planned for
    Ruby 1.9 or 2.0?

    Thanks for your consideration.
    --
    Posted via http://www.ruby-forum.com/.
     
    Suraj Kurapati, Jan 30, 2009
    #1
    1. Advertising

  2. Hi --

    On Fri, 30 Jan 2009, Suraj Kurapati wrote:

    > Hello,
    >
    > I was under the impresssion that Ruby 1.9 will provide
    > Object#singleton_class (or #eigen_class or #meta_class), which would
    > save us the trouble of writing "class << self; self; end" everywhere.
    >
    > But in Ruby 1.9.1-rc2, I do not see this:
    >
    >>> RUBY_DESCRIPTION

    > => "ruby 1.9.1p0 (2009-01-20 revision 21700) [i686-linux]"
    >
    >>> Object.instance_methods.grep(/class|singleton|eigen|meta/)

    > => [:class, :singleton_methods, :define_singleton_method]
    >
    > Was Object#singleton_class (or #eigen_class or #meta_class) planned for
    > Ruby 1.9 or 2.0?


    Not that I remember hearing about. I'd certainly like to see it.


    David

    --
    David A. Black / Ruby Power and Light, LLC
    Ruby/Rails consulting & training: http://www.rubypal.com
    Coming in 2009: The Well-Grounded Rubyist (http://manning.com/black2)

    http://www.wishsight.com => Independent, social wishlist management!
     
    David A. Black, Jan 30, 2009
    #2
    1. Advertising

  3. On Fri, Jan 30, 2009 at 10:28 AM, Yukihiro Matsumoto <> wrote:
    > Hi,
    >
    > In message "Re: Object#singleton_class in Ruby 1.9?"
    > on Fri, 30 Jan 2009 20:15:17 +0900, "David A. Black" <> writes:
    >
    > |> Was Object#singleton_class (or #eigen_class or #meta_class) planned for
    > |> Ruby 1.9 or 2.0?
    > |
    > |Not that I remember hearing about. I'd certainly like to see it.
    >
    > We still don't have consensus on the name. eigenclass?
    > In that case, should we rename singleton_method to eigenmethod?


    I wonder if this controversy has died down. There are people with
    their favorites, sure, but does anyone really oppose singleton_class?

    -greg


    --
    Technical Blaag at: http://blog.majesticseacreature.com
    Non-tech stuff at: http://metametta.blogspot.com
    "Ruby Best Practices" Book now in O'Reilly Roughcuts:
    http://rubybestpractices.com
     
    Gregory Brown, Jan 30, 2009
    #3
  4. Suraj Kurapati

    James Gray Guest

    On Jan 30, 2009, at 9:47 AM, Gregory Brown wrote:

    > On Fri, Jan 30, 2009 at 10:28 AM, Yukihiro Matsumoto <
    > > wrote:
    >> Hi,
    >>
    >> In message "Re: Object#singleton_class in Ruby 1.9?"
    >> on Fri, 30 Jan 2009 20:15:17 +0900, "David A. Black" <
    >> > writes:

    >>
    >> |> Was Object#singleton_class (or #eigen_class or #meta_class)
    >> planned for
    >> |> Ruby 1.9 or 2.0?
    >> |
    >> |Not that I remember hearing about. I'd certainly like to see it.
    >>
    >> We still don't have consensus on the name. eigenclass?
    >> In that case, should we rename singleton_method to eigenmethod?

    >
    > I wonder if this controversy has died down. There are people with
    > their favorites, sure, but does anyone really oppose singleton_class?


    I'm for singleton_class. It's what the official documentation has
    used for a long time now. It's also not like it will be the only
    overloaded term in computing.

    James Edward Gray II
     
    James Gray, Jan 30, 2009
    #4
  5. Suraj Kurapati

    Gary Wright Guest

    On Jan 30, 2009, at 10:53 AM, James Gray wrote:
    > I'm for singleton_class. It's what the official documentation has
    > used for a long time now. It's also not like it will be the only
    > overloaded term in computing.



    eigenton_class? :)

    eigen_class or singleton_class doesn't really matter to
    me at this point but I do feel strongly that the object
    returned by:

    (class <<obj; self; end)

    should be available via a simple method call rather
    than only via that expression.

    Gary Wright
     
    Gary Wright, Jan 30, 2009
    #5
  6. Yukihiro Matsumoto wrote:
    > Hi,
    >
    > In message "Re: Object#singleton_class in Ruby 1.9?"
    > on Fri, 30 Jan 2009 20:15:17 +0900, "David A. Black"
    > <> writes:
    >
    > |> Was Object#singleton_class (or #eigen_class or #meta_class) planned for
    > |> Ruby 1.9 or 2.0?
    > |
    > |Not that I remember hearing about. I'd certainly like to see it.
    >
    > We still don't have consensus on the name. eigenclass?
    > In that case, should we rename singleton_method to eigenmethod?


    Since you make mention of "eigenclass", that would seem to be your bent.
    And I say, go for it! "eigenmethod"? Fantastic! Do it, do it, do it!

    It may be Germanic, but I for one like the shorter method names anyway.
    And certainly _Why has done enough for Ruby to deserve a little of his
    charm to shine through the language... it will just give Ruby another
    unique touch that her fans can revel in. Not to mention, no more
    Singleton vs. singleton controversy.

    Big smiles and all thumbs up,

    T.
    --
    Posted via http://www.ruby-forum.com/.
     
    Thomas Sawyer, Jan 30, 2009
    #6
  7. Yukihiro Matsumoto wrote:
    > Hi,
    >
    > In message "Re: Object#singleton_class in Ruby 1.9?"
    > on Fri, 30 Jan 2009 20:15:17 +0900, "David A. Black"
    > <> writes:
    >
    > |> Was Object#singleton_class (or #eigen_class or #meta_class) planned for
    > |> Ruby 1.9 or 2.0?
    > |
    > |Not that I remember hearing about. I'd certainly like to see it.
    >
    > We still don't have consensus on the name. eigenclass?


    Sorry, I only mentioned the other names because they were all proposed
    when we first discussed this (back in 2006, I think). Ruby was the
    first language where I learned the concept of "singleton class" (not the
    design pattern) so I think it makes sense to keep that name.

    > In that case, should we rename singleton_method to eigenmethod?


    Is this not a larger (disruptive) change than simply adding a new
    Object#singleton_class method?

    Thanks for your consideration.
    --
    Posted via http://www.ruby-forum.com/.
     
    Suraj Kurapati, Jan 30, 2009
    #7
  8. Thomas Sawyer wrote:
    > Yukihiro Matsumoto wrote:
    >> We still don't have consensus on the name. eigenclass?
    >> In that case, should we rename singleton_method to eigenmethod?

    >
    > Since you make mention of "eigenclass", that would seem to be your bent.
    > And I say, go for it! "eigenmethod"? Fantastic! Do it, do it, do it!


    In that case, could we make the names more readable by adding an
    underscore after "eigen"? I find it more difficult to parse the names
    otherwise.

    Object#eigen_class
    Object#eigen_methods
    Object#define_eigen_method

    > Not to mention, no more Singleton vs. singleton controversy.


    This is indeed a good benefit.

    Thanks for your consideration.
    --
    Posted via http://www.ruby-forum.com/.
     
    Suraj Kurapati, Jan 30, 2009
    #8
  9. Suraj Kurapati wrote:
    > Thomas Sawyer wrote:
    >> Yukihiro Matsumoto wrote:
    >>> We still don't have consensus on the name. eigenclass?
    >>> In that case, should we rename singleton_method to eigenmethod?

    >>
    >> Since you make mention of "eigenclass", that would seem to be your bent.
    >> And I say, go for it! "eigenmethod"? Fantastic! Do it, do it, do it!

    >
    > In that case, could we make the names more readable by adding an
    > underscore after "eigen"? I find it more difficult to parse the names
    > otherwise.
    >
    > Object#eigen_class
    > Object#eigen_methods
    > Object#define_eigen_method


    Interesting, I find the other more readable, 'class' is like a suffix to
    me, along the lines of 'name' in methods like #basename and #dirname.

    Just personal preference of course. I'm don't think there is any true
    rational for one over the other.

    T.
    --
    Posted via http://www.ruby-forum.com/.
     
    Thomas Sawyer, Jan 30, 2009
    #9
  10. David A. Black wrote:
    > Hi --
    >
    > On Sat, 31 Jan 2009, Yukihiro Matsumoto wrote:
    >
    >> We still don't have consensus on the name. eigenclass?
    >> In that case, should we rename singleton_method to eigenmethod?

    >
    > No, *please* don't. It would mean having to re-edit books as well as
    > code.... There's been enough change recently :)


    David! How else are you supposed to sell 2nd and 3rd editions! ;)

    T.
    --
    Posted via http://www.ruby-forum.com/.
     
    Thomas Sawyer, Jan 30, 2009
    #10
  11. Thomas Sawyer wrote:
    > Suraj Kurapati wrote:
    >> In that case, could we make the names more readable by adding an
    >> underscore after "eigen"? I find it more difficult to parse the names
    >> otherwise.
    >>
    >> Object#eigen_class
    >> Object#eigen_methods
    >> Object#define_eigen_method

    >
    > Interesting, I find the other more readable, 'class' is like a suffix to
    > me, along the lines of 'name' in methods like #basename and #dirname.


    The problem I have with words like "basename" is that, to me, they are
    not actually words. For example, I pronounce "basename" as two separate
    words "base, name" (with a brief pause in between) not as a continuous
    word "basen-a-me" (without any pause in between).

    The same applies to "dirname", which I pronounce as "dir, name". In
    contrast, "singleton" is actually pronounced continuously as
    "sin-gel-ton", not as "single, ton", so I have no need to insert
    underscores in that word.

    In short, how a word is pronounced tells me when to insert underscores.

    > Just personal preference of course. I'm don't think there is any true
    > rational for one over the other.


    I beg to differ and I think there is a rationale (see above).

    Thanks for your consideration.
    --
    Posted via http://www.ruby-forum.com/.
     
    Suraj Kurapati, Jan 30, 2009
    #11
  12. On Fri, Jan 30, 2009 at 4:47 PM, Gregory Brown
    <> wrote:
    > I wonder if this controversy has died down. There are people with
    > their favorites, sure, but does anyone really oppose singleton_class?


    singleton_class is definitely the best (specially when we consider
    that word 'signleton' already appeared in ruby). What I don't like in
    "eigenclass" is that it's not english word (AFAIR it's from germany
    'egein' word).

    --=20
    Pozdrawiam

    Rados=B3aw Bu=B3at
    http://radarek.jogger.pl - m=F3j blog
     
    Rados³aw Bu³at, Jan 30, 2009
    #12
  13. Suraj Kurapati wrote:

    >> Just personal preference of course. I'm don't think there is any true
    >> rationale for one over the other.

    >
    > I beg to differ and I think there is a rationale (see above).


    Never_the_less this is English, a close relative of German, and it these
    languages conjoined words are common_place.

    T.

    --
    Posted via http://www.ruby-forum.com/.
     
    Thomas Sawyer, Jan 30, 2009
    #13
  14. Thomas Sawyer wrote:
    > Suraj Kurapati wrote:
    >
    >>> Just personal preference of course. I'm don't think there is any true
    >>> rationale for one over the other.

    >>
    >> I beg to differ and I think there is a rationale (see above).

    >
    > Never_the_less this is English, a close relative of German, and in these
    > languages conjoined words are common_place.


    Good point and excellent illustration! Until seeing your example, I
    never realized how well underscores flow with text, in comparison to
    hyphens:

    nevertheless vs. never-the-less vs. never_the_less vs.
    neverTheLess
    commonplace vs. common-place vs. common_place vs.
    commonPlace

    Of all the typographic conventions listed in the above example, I
    heavily prefer snake_case, which is thankfully prevalent in Ruby. This
    is one aspect of Ruby that I found very attractive, compared to, say,
    Python, where the firstconventionintheaboveexample is prevalent. (A
    personal preference, I agree.)

    Generally speaking, it's surprising that a better typographic convention
    would arise from computer science rather than from literature. Perhaps
    we may someday find that, in the increasingly digital future, people
    would begin using under_scores as an alternative to the traditional
    process of compound words being initially hyphenated (e.g. under-score)
    and later not hyphenated (e.g. underscore).

    Cheers.
    --
    Posted via http://www.ruby-forum.com/.
     
    Suraj Kurapati, Jan 30, 2009
    #14
  15. On Fri, Jan 30, 2009 at 5:46 PM, Gary Wright <> wrote:
    >
    > On Jan 30, 2009, at 10:53 AM, James Gray wrote:
    >>
    >> I'm for singleton_class. It's what the official documentation has used
    >> for a long time now. It's also not like it will be the only overloaded term
    >> in computing.

    >
    >
    > eigenton_class? :)
    >
    > eigen_class or singleton_class doesn't really matter to
    > me at this point but I do feel strongly that the object
    > returned by:
    >
    > (class <<obj; self; end)
    >
    > should be available via a simple method call rather
    > than only via that expression.


    I completely agree with this point of view. I don't mind which name
    gets chosen, but please, choose one :).

    Jesus.
     
    Jesús Gabriel y Galán, Jan 30, 2009
    #15
  16. Jesús Gabriel y Galán wrote:
    > On Fri, Jan 30, 2009 at 5:46 PM, Gary Wright <> wrote:
    >> eigen_class or singleton_class doesn't really matter to
    >> me at this point but I do feel strongly that the object
    >> returned by:
    >>
    >> (class <<obj; self; end)
    >>
    >> should be available via a simple method call rather
    >> than only via that expression.

    >
    > I completely agree with this point of view. I don't mind which name
    > gets chosen, but please, choose one :).
    >
    > Jesus.


    I thought you were making an exclamation, until I realized that was
    actually your name. :)

    Hope that doesn't offend --with a name like mine I know how it can be.
    It just gave me a good laugh, so I thought I'd share it.

    T.
    --
    Posted via http://www.ruby-forum.com/.
     
    Thomas Sawyer, Jan 31, 2009
    #16
  17. On Sat, Jan 31, 2009 at 6:06 AM, Thomas Sawyer <> wrote:
    > Jes=FAs Gabriel y Gal=E1n wrote:


    > I thought you were making an exclamation, until I realized that was
    > actually your name. :)
    >
    > Hope that doesn't offend --with a name like mine I know how it can be.
    > It just gave me a good laugh, so I thought I'd share it.


    No problem. In Spain my name is used as an exclamation when someone
    sneezes, so I'm pretty much used to these kind of things. In any case,
    I also find it funny sometimes...

    Jesus !

    PS: I might start changing the dot for an exclamation mark in my signature =
    :)
     
    Jesús Gabriel y Galán, Jan 31, 2009
    #17
  18. On Fri, Jan 30, 2009 at 3:28 PM, Yukihiro Matsumoto <> wrote:
    > Hi,
    >
    > In message "Re: Object#singleton_class in Ruby 1.9?"
    > on Fri, 30 Jan 2009 20:15:17 +0900, "David A. Black" <> writes:
    >
    > |> Was Object#singleton_class (or #eigen_class or #meta_class) planned for
    > |> Ruby 1.9 or 2.0?
    > |
    > |Not that I remember hearing about. I'd certainly like to see it.
    >
    > We still don't have consensus on the name. eigenclass?
    > In that case, should we rename singleton_method to eigenmethod?
    >
    > matz.


    Personally, I prefer singleton_class. But I would rather it had an
    official name than my preference held anything up.

    I suspect there is a strong consensus that it should be named,
    whatever the name. I doubt we'll ever get consensus on ~what~ that
    name should be. :)

    Regards,
    Sean
     
    Sean O'Halpin, Jan 31, 2009
    #18
  19. On Sat, Jan 31, 2009 at 8:12 AM, Sean O'Halpin <> wrote:
    > On Fri, Jan 30, 2009 at 3:28 PM, Yukihiro Matsumoto <> wrote:
    >> Hi,
    >>
    >> In message "Re: Object#singleton_class in Ruby 1.9?"
    >> on Fri, 30 Jan 2009 20:15:17 +0900, "David A. Black" <> writes:
    >>
    >> |> Was Object#singleton_class (or #eigen_class or #meta_class) planned for
    >> |> Ruby 1.9 or 2.0?
    >> |
    >> |Not that I remember hearing about. I'd certainly like to see it.
    >>
    >> We still don't have consensus on the name. eigenclass?
    >> In that case, should we rename singleton_method to eigenmethod?
    >>
    >> matz.

    >
    > Personally, I prefer singleton_class. But I would rather it had an
    > official name than my preference held anything up.
    >
    > I suspect there is a strong consensus that it should be named,
    > whatever the name. I doubt we'll ever get consensus on ~what~ that
    > name should be. :)


    Definitely. I was implying that I don't think *too* many people hate
    singleton_class, but don't get me wrong, even if matz added
    Object#matz_is_awesome and had it do this operation, I'd be happy. :)

    -greg

    --
    Technical Blaag at: http://blog.majesticseacreature.com
    Non-tech stuff at: http://metametta.blogspot.com
    "Ruby Best Practices" Book now in O'Reilly Roughcuts:
    http://rubybestpractices.com
     
    Gregory Brown, Jan 31, 2009
    #19
  20. Suraj Kurapati

    Robert Dober Guest

    On Fri, Jan 30, 2009 at 4:28 PM, Yukihiro Matsumoto <> wrote:
    > Hi,
    >
    > In message "Re: Object#singleton_class in Ruby 1.9?"
    > on Fri, 30 Jan 2009 20:15:17 +0900, "David A. Black" <> writes:
    >
    > |> Was Object#singleton_class (or #eigen_class or #meta_class) planned for
    > |> Ruby 1.9 or 2.0?
    > |
    > |Not that I remember hearing about. I'd certainly like to see it.
    >
    > We still don't have consensus on the name. eigenclass?
    > In that case, should we rename singleton_method to eigenmethod?
    >
    > matz.


    Actually I am totally against it, in core that is. It would be nice to
    have a standard library extension for this, e.g. meta-ruby.
    I was really impressed about by David's keynote at Rubyconf. Just
    thought to share this thoughts in case I am not a minority.
    Cheers
    Robert
    >




    --
    It is change, continuing change, inevitable change, that is the
    dominant factor in society today. No sensible decision can be made any
    longer without taking into account not only the world as it is, but
    the world as it will be ... ~ Isaac Asimov
     
    Robert Dober, Jan 31, 2009
    #20
    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. jon wayne
    Replies:
    9
    Views:
    712
    Jim Langston
    Sep 22, 2005
  2. Replies:
    0
    Views:
    220
  3. anne001
    Replies:
    1
    Views:
    478
  4. Phrogz
    Replies:
    4
    Views:
    233
    Austin Ziegler
    Sep 6, 2006
  5. Pokkai Dokkai
    Replies:
    20
    Views:
    257
    Pokkai Dokkai
    Apr 17, 2008
Loading...

Share This Page