1
0
Fork 0
mirror of https://github.com/pry/pry.git synced 2022-11-09 12:35:05 -05:00

lib/pry/commands/ls/*.rb: tweak visibility of the methods

This commit is contained in:
Kyrylo Silin 2013-12-01 04:48:19 +02:00
parent e7f0872de8
commit 11c3e335e9
11 changed files with 36 additions and 13 deletions

View file

@ -24,6 +24,8 @@ class Pry
output_section('constants', grep.regexp[format(mod, constants)])
end
private
def format(mod, constants)
constants.sort_by(&:downcase).map do |name|
if const = (!mod.autoload?(name) && (mod.const_get(name) || true) rescue nil)

View file

@ -8,6 +8,13 @@ class Pry
@target = target
end
def write_out
return false unless correct_opts?
output_self
end
private
def color(type, str)
Pry::Helpers::Text.send(Pry.config.ls.send(:"#{type}_color"), str)
end
@ -24,11 +31,6 @@ class Pry
Pry::ColorPrinter.pp(value, '')
end
def write_out
return false unless correct_opts?
output_self
end
def correct_opts?
@default_switch
end

View file

@ -29,6 +29,8 @@ class Pry
output_section('global variables', grep.regexp[variables])
end
private
def format(globals)
globals.sort_by(&:downcase).map do |name|
if PSEUDO_GLOBALS.include?(name)

View file

@ -28,6 +28,8 @@ class Pry
ivars_out + kvars_out
end
private
def format(type, vars)
vars.sort_by { |var| var.to_s.downcase }.map { |var| color(type, var) }
end

View file

@ -1,5 +1,7 @@
module Pry::Command::Ls::Interrogateable
private
def interrogating_a_module?
Module === @interrogatee
end

View file

@ -1,5 +1,7 @@
module Pry::Command::Ls::JRubyHacks
private
# JRuby creates lots of aliases for methods imported from java in an attempt
# to make life easier for ruby programmers. (e.g. getFooBar becomes
# get_foo_bar and foo_bar, and maybe foo_bar? if it returns a Boolean). The

View file

@ -18,6 +18,8 @@ class Pry
output_section('locals', format(local_vars))
end
private
def format(locals)
locals.sort_by(&:downcase).map do |name|
if @sticky_locals.include?(name.to_sym)

View file

@ -17,6 +17,8 @@ class Pry
format(name_value_pairs).join('')
end
private
def format(name_value_pairs)
name_value_pairs.sort_by { |name, value|
value.to_s.size

View file

@ -19,10 +19,6 @@ class Pry
@verbose_switch = opts[:verbose]
end
def correct_opts?
super || @instance_methods_switch || @ppp_switch || @no_user_opts
end
def output_self
methods = all_methods.group_by(&:owner)
# Reverse the resolution order so that the most useful information
@ -34,6 +30,13 @@ class Pry
end.join('')
end
private
def correct_opts?
super || @instance_methods_switch || @ppp_switch || @no_user_opts
end
# Get a lambda that can be used with `take_while` to prevent over-eager
# traversal of the Object's ancestry graph.
def below_ceiling

View file

@ -4,6 +4,8 @@ module Pry::Command::Ls::MethodsHelper
include Pry::Command::Ls::JRubyHacks
private
# Get all the methods that we'll want to output.
def all_methods(instance_methods = false)
methods = if instance_methods || @instance_methods_switch

View file

@ -13,10 +13,6 @@ class Pry
@no_user_opts = no_user_opts
end
def correct_opts?
@no_user_opts && interrogating_a_module?
end
def output_self
methods = all_methods(true).select do |m|
m.owner == @interrogatee && grep.regexp[m.name]
@ -25,6 +21,12 @@ class Pry
output_section(heading, format(methods))
end
private
def correct_opts?
@no_user_opts && interrogating_a_module?
end
end
end
end