Module: Pry::Helpers::BaseHelpers

Extended by:
BaseHelpers
Includes:
Platform
Included in:
Command, Command::Cat::AbstractFormatter, Command::FindMethod, Command::ShowInfo, CommandSet, Editor, BaseHelpers, Indent, Method, Method, WrappedModule
Defined in:
lib/pry/helpers/base_helpers.rb

Instance Method Summary collapse

Methods included from Platform

#jruby?, #jruby_19?, #known_engines, #linux?, #mac_osx?, #mri?, #mri_19?, #mri_2?, #rbx?, #windows?, #windows_ansi?

Instance Method Details

#colorize_code(code) ⇒ Object



47
48
49
# File 'lib/pry/helpers/base_helpers.rb', line 47

def colorize_code(code)
  CodeRay.scan(code, :ruby).term
end

#command_dependencies_met?(options) ⇒ Boolean



36
37
38
39
40
41
# File 'lib/pry/helpers/base_helpers.rb', line 36

def command_dependencies_met?(options)
  return true if !options[:requires_gem]
  Array(options[:requires_gem]).all? do |g|
    Pry::Rubygem.installed?(g)
  end
end

#find_command(name, set = Pry::Commands) ⇒ Object



25
26
27
28
29
30
# File 'lib/pry/helpers/base_helpers.rb', line 25

def find_command(name, set = Pry::Commands)
  command_match = set.find do |_, command|
    (listing = command.options[:listing]) == name && listing != nil
  end
  command_match.last if command_match
end

#heading(text) ⇒ Object

formatting



56
57
58
59
# File 'lib/pry/helpers/base_helpers.rb', line 56

def heading(text)
  text = "#{text}\n--"
  "\e[1m#{text}\e[0m"
end

#highlight(string, regexp, highlight_color = :bright_yellow) ⇒ Object



51
52
53
# File 'lib/pry/helpers/base_helpers.rb', line 51

def highlight(string, regexp, highlight_color=:bright_yellow)
  string.gsub(regexp) { |match| "<#{highlight_color}>#{match}</#{highlight_color}>" }
end

#not_a_real_file?(file) ⇒ Boolean



32
33
34
# File 'lib/pry/helpers/base_helpers.rb', line 32

def not_a_real_file?(file)
  file =~ /^(\(.*\))$|^<.*>$/ || file =~ /__unknown__/ || file == "" || file == "-e"
end

#safe_send(obj, method, *args, &block) ⇒ Object

Acts like send but ignores any methods defined below Object or Class in the inheritance hierarchy. This is required to introspect methods on objects like Net::HTTP::Get that have overridden the method method.



20
21
22
# File 'lib/pry/helpers/base_helpers.rb', line 20

def safe_send(obj, method, *args, &block)
  (Module === obj ? Module : Object).instance_method(method).bind(obj).call(*args, &block)
end

#silence_warningsObject



6
7
8
9
10
11
12
13
14
# File 'lib/pry/helpers/base_helpers.rb', line 6

def silence_warnings
  old_verbose = $VERBOSE
  $VERBOSE = nil
  begin
    yield
  ensure
    $VERBOSE = old_verbose
  end
end

#stagger_output(text, out = nil) ⇒ Object

Send the given text through the best available pager (if Pry.config.pager is enabled). Infers where to send the output if used as a mixin. DEPRECATED.



64
65
66
67
68
69
70
# File 'lib/pry/helpers/base_helpers.rb', line 64

def stagger_output(text, out = nil)
  if defined?(_pry_) && _pry_
    _pry_.pager.page text
  else
    Pry.new.pager.page text
  end
end

#use_ansi_codes?Boolean



43
44
45
# File 'lib/pry/helpers/base_helpers.rb', line 43

def use_ansi_codes?
  windows_ansi? || ENV['TERM'] && ENV['TERM'] != "dumb"
end