Module: Pry::MethodInfo

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

Constant Summary collapse

METHOD_INSPECT_PATTERN =

Returns a pattern that matches method_instance.inspect.

Returns:

  • (Regexp)

    a pattern that matches method_instance.inspect

if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("2.7.0")
  %r{\A
    \#<
      (?:Unbound)?Method:\s
      (.+) # Method owner such as "BigDecimal"
      ([\#\.].+?) # Method signature such as ".finite?" or "#finite?"
      \(.*\) # Param list
      (?:
        \s/.+\.rb:\d+ # Source location
      )?
      .* # Sometimes there's gibberish like "<main>:0", we ignore that
    >
  \z}x
else
  %r{\A
    \#<
      (?:Unbound)?Method:\s
      (.+) # Method owner such as "BigDecimal"
      ([\#\.].+?) # Method signature such as ".finite?" or "#finite?"
      (?:
        \(.*\) # Param list
      )?
    >
  \z}x
end

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



56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/pry-doc/pry_ext/method_info.rb', line 56

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



73
74
75
76
# File 'lib/pry-doc/pry_ext/method_info.rb', line 73

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



45
46
47
48
# File 'lib/pry-doc/pry_ext/method_info.rb', line 45

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