Sha256: 5bdbf7b596c294cf0c214ff74416871e0471e50b7dde08f0a8a3aa52061fe53d

Contents?: true

Size: 1.21 KB

Versions: 1

Compression:

Stored size: 1.21 KB

Contents

module Mirrors
  # Methods here follow the pattern of:
  # <target>_<instance or singleton>_<invoke or method>
  #
  # * target is the owner of the method
  # * instance or singleton indicates whether we want an instance method or a
  #   singleton method from the target
  # * invoke calls the method on a receiver, which must be compatible with the
  #   method. method returns the method to bind to whatever receiver you want.

  @unbound_module_instance_methods = {}
  @unbound_class_singleton_methods = {}
  @unbound_kernel_instance_methods = {}

  def self.module_instance_invoke(receiver, msg)
    module_instance_method(msg).bind(receiver).call
  end

  def self.module_instance_method(msg)
    @unbound_module_instance_methods[msg] ||= Module.instance_method(msg)
  end

  def self.class_singleton_invoke(receiver, msg)
    class_singleton_method(msg).bind(receiver).call
  end

  def self.class_singleton_method(msg)
    @unbound_class_singleton_methods[msg] ||= Class.method(msg).unbind
  end

  def self.kernel_instance_invoke(receiver, msg)
    kernel_instance_method(msg).bind(receiver).call
  end

  def self.kernel_instance_method(msg)
    @unbound_kernel_instance_methods[msg] ||= Kernel.instance_method(msg)
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
mirrors-0.0.3 lib/mirrors/invoke.rb