Permalink
Browse files

refactored binding tests into binding_for() method

  • Loading branch information...
1 parent 558fcb3 commit 4fcf81b97601945945f43311532c164a93b44d7c @banister committed Dec 8, 2010
Showing with 12 additions and 8 deletions.
  1. +12 −8 lib/pry.rb
View
20 lib/pry.rb
@@ -24,10 +24,7 @@ class << self
# loop
def self.repl(target=TOPLEVEL_BINDING)
- if !target.is_a?(Binding)
- target = target.instance_eval { binding }
- end
-
+ target = binding_for(target)
target_self = target.eval('self')
puts session_start_msg.call(target_self)
@@ -49,10 +46,7 @@ class << self
# print
def self.rep(target=TOPLEVEL_BINDING)
- if !target.is_a?(Binding)
- target = target.instance_eval { binding }
- end
-
+ target = binding_for(target)
value = re(target)
case value
when Exception
@@ -64,13 +58,15 @@ def self.rep(target=TOPLEVEL_BINDING)
# eval
def self.re(target=TOPLEVEL_BINDING)
+ target = binding_for(target)
target.eval r(target)
rescue StandardError => e
e
end
# read
def self.r(target=TOPLEVEL_BINDING)
+ target = binding_for(target)
eval_string = ""
loop do
val = Readline.readline(prompt(eval_string, target), true)
@@ -111,6 +107,14 @@ def self.valid_expression?(code)
true
end
+ def self.binding_for(target)
+ if target.is_a?(Binding)
+ target
+ else
+ target.instance_eval { binding }
+ end
+ end
+
def self.kill
@dead = true
end

0 comments on commit 4fcf81b

Please sign in to comment.