Class: Pry

Inherits:
Object
  • Object
show all
Defined in:
lib/pry-syntax-hacks.rb

Defined Under Namespace

Classes: Command

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.hack_line(eval_string) ⇒ Object



9
10
11
12
13
14
15
# File 'lib/pry-syntax-hacks.rb', line 9

def self.hack_line(eval_string)
  eval_string.gsub!(/\.(@[a-z0-9_]+)/, '.instance_variable_get("\1")')
  eval_string.gsub!(/\.:([a-z0-9_]+[?!]?)/, '.method(:\1)')
  eval_string.gsub!(/\.!([a-z0-9_]+[?!]?)([ \(])(?=(.*))/) { ".send#{$2}:#{$1}#{$3 == ""?"":","}" }
  eval_string.gsub!(/(^|[\s\[{>(<=])((\.\.\/)+)([a-z0-9_@]+)/) { "#{$1}_pry_.binding_or_raise(#{-1 - $2.size / 3}).eval('#{$4}')" }
  eval_string
end

Instance Method Details

#binding_or_raise(n) ⇒ Object



17
18
19
# File 'lib/pry-syntax-hacks.rb', line 17

def binding_or_raise(n)
  binding_stack[n] or raise "no parent binding"
end

#old_retrieve_lineObject



2
# File 'lib/pry-syntax-hacks.rb', line 2

alias_method :old_retrieve_line, :retrieve_line

#retrieve_line(eval_string, *args) ⇒ Object



4
5
6
7
# File 'lib/pry-syntax-hacks.rb', line 4

def retrieve_line(eval_string, *args)
  old_retrieve_line(eval_string, *args)
  Pry.hack_line(eval_string)
end