mirror of
https://github.com/pry/pry.git
synced 2022-11-09 12:35:05 -05:00
first commit
This commit is contained in:
commit
53e40e9865
2 changed files with 58 additions and 0 deletions
42
lib/pry.rb
Normal file
42
lib/pry.rb
Normal file
|
@ -0,0 +1,42 @@
|
|||
require 'rubygems'
|
||||
require 'readline'
|
||||
require 'ruby_parser'
|
||||
|
||||
class RubyParser
|
||||
def self.valid?(code)
|
||||
new.parse(code)
|
||||
rescue Racc::ParseError
|
||||
false
|
||||
else
|
||||
true
|
||||
end
|
||||
end
|
||||
|
||||
def pry(target)
|
||||
eval_string = ""
|
||||
while true
|
||||
prompt = ""
|
||||
if eval_string.empty?
|
||||
prompt = "> "
|
||||
else
|
||||
prompt = "* "
|
||||
end
|
||||
|
||||
val = Readline.readline(prompt, true)
|
||||
eval_string += val
|
||||
|
||||
if val == "!"
|
||||
eval_string = ""
|
||||
puts "refreshing REPL state"
|
||||
break
|
||||
end
|
||||
|
||||
exit if val == "quit"
|
||||
break if RubyParser.valid?(eval_string)
|
||||
end
|
||||
begin
|
||||
puts "=> #{target.instance_eval(eval_string).inspect}"
|
||||
rescue StandardError => e
|
||||
puts "#{e.message}"
|
||||
end
|
||||
end
|
16
lib/target.rb
Normal file
16
lib/target.rb
Normal file
|
@ -0,0 +1,16 @@
|
|||
require './pry'
|
||||
|
||||
o = Object.new
|
||||
class << o
|
||||
def pig;
|
||||
puts "pig!!!"
|
||||
end
|
||||
|
||||
def horse?
|
||||
puts "HORSEY LOL"
|
||||
end
|
||||
end
|
||||
|
||||
5.times {
|
||||
pry(o)
|
||||
}
|
Loading…
Reference in a new issue