Sha256: 7df5efc60fbf39c4d3d6075cfd1746e5edae3db300a980415249534098249b67

Contents?: true

Size: 711 Bytes

Versions: 1

Compression:

Stored size: 711 Bytes

Contents

module MethodInfoMethod
  def method_info
    MethodInfo.new(self)
  end
end

class Object
  include MethodInfoMethod
end

class MethodInfo
  def initialize(object)
    @object = object
    unless @object.singleton_methods.empty?
      @eigenclass = class << object; self; end
    end
  end

  def ancestors
    @ancestors = []
    if @eigenclass
      @ancestors << @eigenclass
    end
    @ancestors += @object.class.ancestors
  end

  def method_owner(method)
    @object.method(method).owner
  end

  def method_owner!(method)
    method_owner(method)
  rescue NameError => e
    begin
      @object.send(method)
      method_owner(:method_missing)
    rescue NoMethodError
      raise e
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
method_info-0.0.0 lib/method_info.rb