Sha256: 7594330821933f4bb4c4d2305f9f06cbb4aca265a6b4786e8f86e1b7ed714dbf

Contents?: true

Size: 658 Bytes

Versions: 6

Compression:

Stored size: 658 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
  #   p K.instance_method!(:hello)   #=> <UnboundMethod: #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

6 entries across 6 versions & 1 rubygems

Version Path
facets-2.8.4 lib/core/facets/module/instance_method.rb
facets-2.8.3 lib/core/facets/module/instance_method.rb
facets-2.8.2 lib/core/facets/module/instance_method.rb
facets-2.8.1 lib/core/facets/module/instance_method.rb
facets-2.8.0 lib/core/facets/module/instance_method.rb
facets-2.7.0 lib/core/facets/module/instance_method.rb