D
David A. Black
Hi --
Aw, come from Ruby already!
Whoops, I snipped the part you were talking about... but aren't they
in Ruby too?
o = Object.new
def o.x; puts "I'm a new method!"; end
Yes; I submitted such an RCR, for Kernel#singleton_class. (I know
about the naming issues, but I'd rather not deviate from what Matz
uses at a given time.) See http://www.rcrchive.net/rcr/show/231
I think that Kernel#singleton_class would work for that purpose, and
would also completely transform people's understanding of the whole
class/singleton-class duality.
David
Coming from Javascript (where every instance is trivially extensible
Aw, come from Ruby already!
directly) that seems somewhat cumbersome.
Whoops, I snipped the part you were talking about... but aren't they
in Ruby too?
o = Object.new
def o.x; puts "I'm a new method!"; end
Do many people write things like:
class Object
def instance_class
class<<self; self; end
end
end
in a common library they re-use frequently? Is there an RCR (or has there
been discussion) about adding a simple method like that to the language, so
you can simply do:
f = Foo.new
f.instance_class.class_eval{ ... }
Yes; I submitted such an RCR, for Kernel#singleton_class. (I know
about the naming issues, but I'd rather not deviate from what Matz
uses at a given time.) See http://www.rcrchive.net/rcr/show/231
Or (what I'm really looking for) perhaps it might be nice to have a
define_method method that worked directly for instances. Hrm, but what would
the syntax be? Perhaps that's not such a good idea.
I think that Kernel#singleton_class would work for that purpose, and
would also completely transform people's understanding of the whole
class/singleton-class duality.
David