summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Mair <jrmair@gmail.com>2013-07-23 17:47:33 -0700
committerJohn Mair <jrmair@gmail.com>2013-07-23 17:47:33 -0700
commitd682b44b40ebedb8de81c9c1facda1904f2eeeaf (patch)
tree0db70c6ec4a82f0c61dfbd5f7c522660f35a3555
parentd59ca6c11b11318e71f7fe7192ecc641a1c8db73 (diff)
parentd6176275b64e10b349870641ea6751b1bbd10ad9 (diff)
downloadpry-d682b44b40ebedb8de81c9c1facda1904f2eeeaf.tar.gz
Merge pull request #952 from hashrocketeer/play_expression
Add expression flag to play
-rw-r--r--lib/pry/commands/play.rb23
-rw-r--r--spec/commands/play_spec.rb19
2 files changed, 41 insertions, 1 deletions
diff --git a/lib/pry/commands/play.rb b/lib/pry/commands/play.rb
index 59ae476f..e9fc5bfa 100644
--- a/lib/pry/commands/play.rb
+++ b/lib/pry/commands/play.rb
@@ -14,6 +14,7 @@ class Pry
play -i 20 --lines 1..3 # assumes lines of the input expression at 20
play -o 4 # the output of of an expression at 4
play Pry#repl -l 1..-1 # play the contents of Pry#repl method
+ play -e 2 # play from specified line until end of valid expression
play hello.rb # play a file
play Rakefile -l 5 # play line 5 of a file
play -d hi # play documentation of hi method
@@ -29,6 +30,8 @@ class Pry
' for replaying methods and leaving the method definition' \
' "open". `amend-line` can then be used to' \
' modify the method.'
+
+ opt.on :e, :expression=, 'Executes until end of valid expression', :as => Integer
end
def process
@@ -39,10 +42,28 @@ class Pry
end
def perform_play
- eval_string << (opts.present?(:open) ? restrict_to_lines(content, (0..-2)) : content)
+ eval_string << content_after_options
run "fix-indent"
end
+ def content_after_options
+ if opts.present?(:open)
+ restrict_to_lines(content, (0..-2))
+ elsif opts.present?(:expression)
+ content_at_expression
+ else
+ content
+ end
+ end
+
+ def content_at_expression
+ code_object.expression_at(opts[:expression])
+ end
+
+ def code_object
+ Pry::Code.new(content)
+ end
+
def should_use_default_file?
!args.first && !opts.present?(:in) && !opts.present?(:out)
end
diff --git a/spec/commands/play_spec.rb b/spec/commands/play_spec.rb
index a8f76a73..68192bac 100644
--- a/spec/commands/play_spec.rb
+++ b/spec/commands/play_spec.rb
@@ -132,5 +132,24 @@ describe "play" do
d.should == 1
end
end
+
+ describe "play -e" do
+ it 'should run an expression from given line number' do
+ def @o.test_method
+ @s = [
+ 1,2,3,
+ 4,5,6
+ ]
+ end
+
+ @t.process_command 'play test_method -e 2'
+ @t.eval_string.should == unindent(<<-STR, 0)
+ @s = [
+ 1,2,3,
+ 4,5,6
+ ]
+ STR
+ end
+ end
end
end