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

first commit

This commit is contained in:
John Mair 2010-12-07 21:11:35 +13:00
commit 53e40e9865
2 changed files with 58 additions and 0 deletions

42
lib/pry.rb Normal file
View 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
View 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)
}