On Nov 12, 10:10 am, Phrogz [email protected] wrote:
How can a method be a first-class object and have #super work?
You mean to unify UnboundMethod and Method. I suppose UnboundMethod
could keep a table of the classes it was in.
madness (which, of course, would need some way to control the
different arity handling), but I’m not seeing it as possible right
now.
[1]http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/179372
Feel free to poke holes in my argument
I’m not so sure about the #initialize thing. I think maybe your
troubles came from lua and how you went about it there. Ruby creates
an object basically like this:
class Class
def new(*a, &b)
o = allocate
o.initialize(*a, &b)
o
end
end
In fact you can use that as a basis for some fun meta-coding.
class Class
alias_method :postinitialize_new, :new
def new(*args, &blk)
o = allocate
a = ancestors
until a.empty?
m = a.pop
if m.method_defined?(‘preinitialize’) or
m.private_method_defined?(‘preinitialize’)
im = instance_method(‘preinitialize’)
im.arity == 0 ? im.bind(o).call : im.bind(o).call(*args,
&blk)
end
end
o.send(:initialize, *args, &blk) if
o.object_class.private_method_defined?(:initialize)
o
end
end
So i don’t see why it can’t be:
class Class
def new(*a, &b)
o = allocate
o.new(*a, &b)
o
end
end
also, from your post, I wish ruby did this always!:
“(For those not familiar with Lua, the colon used when defining a
function means “Hey, please create an implicit first parameter named
‘self’, because I’m too lazy to type it each time.” This is why I can
pass the ‘self’ from the subclasses to the parent method, and have the
initializer operate on it instead.)”
T.