Skip to content

Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →

instance method

Module#instance_method

(::interned name) -> ::UnboundMethod
mod.instance_method(symbol) → unbound_method

Returns an UnboundMethod representing the given instance method in mod. See UnboundMethod about how to utilize it

Example
class Person
  def initialize(name)
    @name = name
  end

  def hi
    puts "Hi, I'm #{@name}!"
  end
end

 dave = Person.new('Dave')
 thomas = Person.new('Thomas')

 hi = Person.instance_method(:hi)
 hi.bind_call(dave)
 hi.bind_call(thomas)

produces:

Hi, I'm Dave!
Hi, I'm Thomas!