# How does Ruby gets bindings?

**URL:** <https://www.ruby-forum.com/t/how-does-ruby-gets-bindings/109486>\
**Category:** Ruby\
**Created:** [July 15, 2007, 6:56pm UTC](https://www.ruby-forum.com/t/how-does-ruby-gets-bindings/109486 "2007-07-15T18:56:00Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![laber](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/67e7ee/32.png) [@laber](https://www.ruby-forum.com/u/laber)\
**Post date:** [July 15, 2007, 6:56pm UTC](https://www.ruby-forum.com/t/how-does-ruby-gets-bindings/109486/1 "2007-07-15T18:56:00Z")

</div>

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\_method(:bar) ) #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.
