mirror of
https://github.com/pry/pry.git
synced 2022-11-09 12:35:05 -05:00
parent
d7b336328c
commit
1cec3111dc
2 changed files with 25 additions and 2 deletions
|
@ -189,8 +189,7 @@ class Pry
|
|||
return unless opts.present?(:constants) || (!has_user_specified_any_options && interrogating_a_module?)
|
||||
|
||||
mod = interrogating_a_module? ? object_to_interrogate : Object
|
||||
constants = mod.constants(true)
|
||||
constants -= (mod.ancestors - [mod]).map(&:constants).flatten unless opts.present?(:verbose)
|
||||
constants = WrappedModule.new(mod).constants(opts.present?(:verbose))
|
||||
output_section("constants", grep[format_constants(mod, constants)])
|
||||
end
|
||||
|
||||
|
|
|
@ -65,6 +65,30 @@ class Pry
|
|||
@doc = nil
|
||||
end
|
||||
|
||||
# Returns an array of the names of the constants accessible in the wrapped
|
||||
# module. This provides a consistent interface between 1.8 and 1.9 and also
|
||||
# avoids the problem of accidentally calling the singleton method
|
||||
# `Module.constants`.
|
||||
# @param [Boolean] inherit (true) Include the names of constants from
|
||||
# included modules?
|
||||
def constants(inherit = true)
|
||||
method = Module.instance_method(:constants).bind(@wrapped)
|
||||
|
||||
# If we're on 1.8, we have to manually remove ancestors' constants. If
|
||||
# we're on 1.9, though, it's better to use the built-in `inherit` param,
|
||||
# since it doesn't do things like incorrectly remove Pry::Config.
|
||||
if method.arity == 0
|
||||
consts = method.call
|
||||
if !inherit
|
||||
consts -= (@wrapped.ancestors - [@wrapped]).map(&:constants).flatten
|
||||
end
|
||||
else
|
||||
consts = method.call(inherit)
|
||||
end
|
||||
|
||||
consts
|
||||
end
|
||||
|
||||
# The prefix that would appear before methods defined on this class.
|
||||
#
|
||||
# i.e. the "String." or "String#" in String.new and String#initialize.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue