Sha256: 7e7fea27e5006bc3b383c7afab21f1b357117b48f837ee240de7e73b78d96b48

Contents?: true

Size: 721 Bytes

Versions: 20

Compression:

Stored size: 721 Bytes

Contents

require 'facets/more/functor.rb'

module Kernel #class Object

  # Returns a Functor that allows one to call any
  # Kernel or Object method bound to self, making it
  # possible to bypass overrides of Kernel and Object
  # methods.
  #
  #   class A
  #     def object_id ; "OBTUSE" ; end
  #   end
  #
  #   c = C.new
  #   c.object_id             #=> "OBTUSE"
  #   c.__self__.object_id    #=> 6664875832
  #
  #--
  # Might this be better named as 'object' or '__object__'?
  # Should this method actually be private?
  #++

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

  #alias_method :self, :__self__

end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
facets-1.3.0 lib/facets/core/kernel/__self__.rb
facets-1.3.1 lib/facets/core/kernel/__self__.rb
facets-1.3.2 lib/facets/core/kernel/__self__.rb
facets-1.3.3 lib/facets/core/kernel/__self__.rb
facets-1.4.0 lib/facets/core/kernel/__self__.rb
facets-1.4.2 lib/facets/core/kernel/__self__.rb
facets-1.4.1 lib/facets/core/kernel/__self__.rb
facets-1.4.3 lib/facets/core/kernel/__self__.rb
facets-1.4.5 lib/facets/core/kernel/__self__.rb
facets-1.4.4 lib/facets/core/kernel/__self__.rb
facets-1.7.0 lib/facets/core/kernel/__self__.rb
facets-1.7.30 lib/facets/core/kernel/__self__.rb
facets-1.7.38 lib/facets/core/kernel/__self__.rb
facets-1.7.46 lib/facets/core/kernel/__self__.rb
facets-1.8.49 lib/facets/core/kernel/__self__.rb
facets-1.8.0 lib/facets/core/kernel/__self__.rb
facets-1.8.20 lib/facets/core/kernel/__self__.rb
facets-1.8.51 lib/facets/core/kernel/__self__.rb
facets-1.8.8 lib/facets/core/kernel/__self__.rb
facets-1.8.54 lib/facets/core/kernel/__self__.rb