Module: Pry::MethodInfo

Defined in:
lib/pry-doc/pry_ext/method_info.rb

Class Method Summary collapse

Class Method Details

.aliases(meth) ⇒ Array<UnboundMethod>

Retrieves aliases of the given method.

Parameters:

  • meth (Method, UnboundMethod)

    The method object

Returns:

  • (Array<UnboundMethod>)

    the aliases of the given method if they exist, otherwise an empty array



22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/pry-doc/pry_ext/method_info.rb', line 22

def aliases(meth)
  owner = meth.owner
  name = meth.name

  (owner.instance_methods + owner.private_instance_methods).uniq.map do |m|
    aliased_method = owner.__send__(:instance_method, m)

    next unless aliased_method == owner.__send__(:instance_method, name)
    next if m == name
    aliased_method
  end.compact!
end

.gem_root(dir) ⇒ String

FIXME: this is unnecessarily limited to ext/ and lib/ directories.

Returns:

  • (String)

    the root directory of a given gem directory



39
40
41
42
# File 'lib/pry-doc/pry_ext/method_info.rb', line 39

def gem_root(dir)
  return unless (index = dir.rindex(%r(/(?:lib|ext)(?:/|$))))
  dir[0..index-1]
end

.info_for(meth) ⇒ YARD::CodeObjects::MethodObject

Retrieve the YARD object that contains the method data.

Parameters:

  • meth (Method, UnboundMethod)

    The method object

Returns:

  • (YARD::CodeObjects::MethodObject)

    the YARD data for the method



11
12
13
14
# File 'lib/pry-doc/pry_ext/method_info.rb', line 11

def info_for(meth)
  cache(meth)
  registry_lookup(meth)
end