R
Rubén Medellín
Hi everyone.
Playing with modules, I come to the following:
#------------------------------
module M
def foo; end
end
module N
def bar; end
end
class C; include M; end
class D; include N; end
module M
define_method( :baz, N.instance_methodbar) ) #Evil!
end
C.new.baz # TypeError: bind argument must be an instance of N
# Everything works as expected. But...
M.instance_method( :baz ).bind( C.new ).call
# => TypeError. bind argument must be an instance of N
M.instance_method( :baz ).bind( D.new ).call
# => TypeError.bind argument must be an instance of M
#--------------------------------
I wonder how bindings are set, if dynamically when the method is
called or since the method is defined.
AFAIK, it's impossible to change the binding of an Unbound method
(except for Evil Ruby, but I'm not that evil). Anyways, I find
somewhat weird this behavior.
Playing with modules, I come to the following:
#------------------------------
module M
def foo; end
end
module N
def bar; end
end
class C; include M; end
class D; include N; end
module M
define_method( :baz, N.instance_methodbar) ) #Evil!
end
C.new.baz # TypeError: bind argument must be an instance of N
# Everything works as expected. But...
M.instance_method( :baz ).bind( C.new ).call
# => TypeError. bind argument must be an instance of N
M.instance_method( :baz ).bind( D.new ).call
# => TypeError.bind argument must be an instance of M
#--------------------------------
I wonder how bindings are set, if dynamically when the method is
called or since the method is defined.
AFAIK, it's impossible to change the binding of an Unbound method
(except for Evil Ruby, but I'm not that evil). Anyways, I find
somewhat weird this behavior.