Sha256: 35caddee765b4438a838a6e59b40662626b8abf314f497c06328a6ce71c914ac
Contents?: true
Size: 674 Bytes
Versions: 10
Compression:
Stored size: 674 Bytes
Contents
$FIRST_CLASS_INSTANCE_METHODS = Hash.new{ |h,k| h[k] = {} } # class Module # 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. 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 end
Version data entries
10 entries across 9 versions & 2 rubygems