Method: Module#instance_method!
- Defined in:
- lib/core/facets/module/instance_method.rb
#instance_method!(s) ⇒ Object
Access method as a singleton object and retain state.
module ::K
def hello
puts "Hello World!"
end
end
K.instance_method!(:hello).inspect #=> "#<UnboundMethod: K#hello>"
NOTE: This is limited to the scope of the current module/class.
18 19 20 21 22 |
# File 'lib/core/facets/module/instance_method.rb', line 18 def instance_method!(s) #( @@__instance_methods__ ||= {} )[s] ||= instance_method(s) # TODO: use class vars for 1.9+ ? #( @__instance_methods__ ||= {} )[s.to_sym] ||= instance_method(s.to_sym) $FIRST_CLASS_INSTANCE_METHODS[self][s.to_sym] ||= instance_method(s.to_sym) end |