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
proc.c
View on GitHub ↗
static VALUE
rb_mod_instance_method(VALUE mod, VALUE vid)
{
ID id = rb_check_id(&vid);
if (!id) {
rb_method_name_error(mod, vid);
}
return mnew_unbound(mod, id, rb_cUnboundMethod, FALSE);
}
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!
See also
#inspect
#instance_methods
#included_modules
#method_added
also in
4.0 · 3.4 · 3.3 · 3.2 · 3.1 · 3.0