# Late binding Method

**URL:** <https://www.ruby-forum.com/t/late-binding-method/141991>\
**Category:** Ruby\
**Created:** [July 2, 2008, 12:59pm UTC](https://www.ruby-forum.com/t/late-binding-method/141991 "2008-07-02T12:59:57Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![james-calivar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/2bfe46/32.png) [@james-calivar](https://www.ruby-forum.com/u/james-calivar)\
**Post date:** [July 2, 2008, 12:59pm UTC](https://www.ruby-forum.com/t/late-binding-method/141991/1 "2008-07-02T12:59:57Z")

</div>

Hello all,

I was just wondering whether it’s at all useful to have a late-binding  
version of Object#method? I’m more concerned about this in the context  
of  
JS.Class, my JavaScript implementation of Ruby’s object system – I tend  
to  
use functional programming with object methods way more in JavaScript. I  
hacked this up:

```
class Method
  attr_writer :name
  alias call_without_late_binding call

  def [](*args, &block)
    args.unshift(@name) if @name
    call_without_late_binding(*args, &block)
  end

  def call(*args, &block)
    args.unshift(@name) if @name
    call_without_late_binding(*args, &block)
  end
end

class Object
  def late_bound(name)
    m = method : __send__
    m.name = name
    m
  end
end

```

I really wnated to subclass Method instead but I couldn’t get that to  
work.  
So we get this:

```
class Foo
  def talk; 'foo'; end
end

f = Foo.new
puts f.talk # => 'foo'

m = f.method :talk
puts m[] # => 'foo'

l = f.late_bound :talk
puts l[] # => 'foo'

class Foo
  def talk; 'bar'; end
end

puts f.talk #=> 'bar'
puts m[] #=> 'foo'
puts l[] #=> 'bar'

```

Any thoughts?
