Sha256: 7b7bde81129920767ec0b085ceaa14ba864a0af39dd4539e0df1c63ada6f9abb

Contents?: true

Size: 561 Bytes

Versions: 1

Compression:

Stored size: 561 Bytes

Contents

require 'facet/functor'

class Object

  # Returns a Functor that allows one to call any
  # Kernel method bound to self.
  #
  #   class A
  #     def object_id ; "OBTUSE" ; end
  #   end
  #
  #   c = C.new
  #   c.object_id             #=> "OBTUSE"
  #   c.instance.object_id    #=> 6664875832
  #
  #--
  # Might this be better named as 'object'?
  #++

  def instance
    @__instance__ ||= Functor.new do |meth, *args|  # &blk|
      Kernel.instance_method(meth).bind(self).call(*args) # ,&blk)
    end
  end

  alias_method :__instance__, :instance

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
facets-1.2.1 lib/facets/core/kernel/instance.rb