I would like to know if I could force this to happen
class A
def bomb ; "bomb" ; end
end
class B ; end
bomb = A.instance_method(:bomb)
b = B.new
bomb.bind(b)
currently it throws the error TypeError: bind argument must be an instance of A
I find this very limiting concerning what I can do with these unbound methods, the possibilities are a bit limiting. In cases like these (and I'm not referring only to idempotent functions) it would make sense right? And an execution error would have sufficed, In case I would be handling variables from A which are not replicated in B. I'd really like to know how to force this bind.
Object.instance_method(:to_s).bind("hello world").call #=> "#<String:0x0000000195e1f0>"
. I don't think it's possible to force the binding in your example though. – FaxonA
would have been amodule
, then it is possible in ruby 2 – Propel