Object#singleton_class in Ruby 1.9?

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/\.

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!

Hi,

···

In message "Re: Object#singleton_class in Ruby 1.9?" on Fri, 30 Jan 2009 20:15:17 +0900, "David A. Black" <dblack@rubypal.com> 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.

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

-greg

···

On Fri, Jan 30, 2009 at 10:28 AM, Yukihiro Matsumoto <matz@ruby-lang.org> wrote:

Hi,

In message "Re: Object#singleton_class in Ruby 1.9?" > on Fri, 30 Jan 2009 20:15:17 +0900, "David A. Black" <dblack@rubypal.com> 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?

--
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

Yukihiro Matsumoto wrote:

Hi,

>> 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.

···

In message "Re: Object#singleton_class in Ruby 1.9?" > on Fri, 30 Jan 2009 20:15:17 +0900, "David A. Black" > <dblack@rubypal.com> writes:

--
Posted via http://www.ruby-forum.com/\.

Hi --

···

On Sat, 31 Jan 2009, 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" <dblack@rubypal.com> 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?

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

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!

Yukihiro Matsumoto wrote:

Hi,

>> 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.

···

In message "Re: Object#singleton_class in Ruby 1.9?" > on Fri, 30 Jan 2009 20:15:17 +0900, "David A. Black" > <dblack@rubypal.com> writes:

--
Posted via http://www.ruby-forum.com/\.

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. :slight_smile:

Regards,
Sean

···

On Fri, Jan 30, 2009 at 3:28 PM, Yukihiro Matsumoto <matz@ruby-lang.org> wrote:

Hi,

In message "Re: Object#singleton_class in Ruby 1.9?" > on Fri, 30 Jan 2009 20:15:17 +0900, "David A. Black" <dblack@rubypal.com> 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.

Hi,

>> 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

···

On Fri, Jan 30, 2009 at 4:28 PM, Yukihiro Matsumoto <matz@ruby-lang.org> wrote:

In message "Re: Object#singleton_class in Ruby 1.9?" > on Fri, 30 Jan 2009 20:15:17 +0900, "David A. Black" <dblack@rubypal.com> writes:

--
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

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

···

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

On Fri, Jan 30, 2009 at 10:28 AM, Yukihiro Matsumoto <matz@ruby-lang.org > > wrote:

Hi,

In message "Re: Object#singleton_class in Ruby 1.9?" >> on Fri, 30 Jan 2009 20:15:17 +0900, "David A. Black" <dblack@rubypal.com >> > 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?

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/\.

David A. Black wrote:

Hi --

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 :slight_smile:

David! How else are you supposed to sell 2nd and 3rd editions! :wink:

T.

···

On Sat, 31 Jan 2009, Yukihiro Matsumoto wrote:

--
Posted via http://www.ruby-forum.com/\.

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).

···

On Fri, Jan 30, 2009 at 4:47 PM, Gregory Brown <gregory.t.brown@gmail.com> wrote:

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

--
Pozdrawiam

Radosław Bułat
http://radarek.jogger.pl - mój blog

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. :slight_smile:

-greg

···

On Sat, Jan 31, 2009 at 8:12 AM, Sean O'Halpin <sean.ohalpin@gmail.com> wrote:

On Fri, Jan 30, 2009 at 3:28 PM, Yukihiro Matsumoto <matz@ruby-lang.org> wrote:

Hi,

In message "Re: Object#singleton_class in Ruby 1.9?" >> on Fri, 30 Jan 2009 20:15:17 +0900, "David A. Black" <dblack@rubypal.com> 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. :slight_smile:

--
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

Robert Dober wrote:

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.

You are against having a method altogether, you mean?

I take it because of the very nature singleton_methods / eigenmethods.
And, I'm guessing, you prescribe to the idea that the only good way to
the singleton "space" is to include modules into it, rather than
defining methods directly. There was a blog post around somewhere to
that effect. It was a good article. I wish I could dig it up now, but
I'm not finding it. Perhaps someone else has the link? In any case, if
that's what you mean, then I generally agree. That article was right,
there rarely is a good reason to define methods directly into the
singleton, one should be including a module with the methods defined in
it instead. The only exception may be class-level methods, but even then
using #extend deserves more merit.

Taking that idea to heart perhaps a reorientation on the matter is
warranted.
Consider this form in place of the usual 'class << self':

  class X
    extend Module.new {
      ...
    }
  end

Not quite as elegant since we can't use do...end. But if #extend could
take a block:

  class X
    extend do
      ...
    end
  end

Then the issue becomes transparent. Even for regular objects:

  obj.extend do
    ...
  end

This is not to say that a singleton_class/eigenclass method would never
be of use, but it would certainly mitigate the need for it a great deal.
(One might also take away from this that a better name for it, if it
were given a method name, would be #extension, but I mention that only
as an aside.)

T.

···

On Fri, Jan 30, 2009 at 4:28 PM, Yukihiro Matsumoto <matz@ruby-lang.org> > wrote:

--
Posted via http://www.ruby-forum.com/\.

I'd like to have a singleton_class method, but even if there isn't
one, I would definitely not like a meta-ruby standard extension. It
suggests much too clear a separation between programming and
metaprogramming in Ruby, whereas part of the coolness of the language
is how interoperative it all is (e.g., the very fact that singleton
methods are stored in classes, which in turn fit into the whole
class/object model in a predictable way).

David

···

On Sun, 1 Feb 2009, Robert Dober wrote:

On Fri, Jan 30, 2009 at 4:28 PM, Yukihiro Matsumoto <matz@ruby-lang.org> wrote:

Hi,

In message "Re: Object#singleton_class in Ruby 1.9?" >> on Fri, 30 Jan 2009 20:15:17 +0900, "David A. Black" <dblack@rubypal.com> 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.

--
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!

eigenton_class? :slight_smile:

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

···

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.

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/\.

I've changing my vote. I now want:

   matz_class()

No one can beat that. :slight_smile:

James Edward Gray II

···

On Jan 31, 2009, at 11:18 AM, Gregory Brown wrote:

On Sat, Jan 31, 2009 at 8:12 AM, Sean O'Halpin > <sean.ohalpin@gmail.com> wrote:

On Fri, Jan 30, 2009 at 3:28 PM, Yukihiro Matsumoto <matz@ruby-lang.org >> > wrote:

Hi,

In message "Re: Object#singleton_class in Ruby 1.9?" >>> on Fri, 30 Jan 2009 20:15:17 +0900, "David A. Black" <dblack@rubypal.com >>> > 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. :slight_smile:

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. :slight_smile:

James Gray wrote:

Gregory Brown wrote:

Matz wrote:

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.

I filed a request for Object#singleton_class in the Ruby Issue Tracking
System:

  http://redmine.ruby-lang.org/issues/show/1082

Thanks for your consideration.

···

--
Posted via http://www.ruby-forum.com/\.