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

Merge pull request #952 from hashrocketeer/play_expression

Add expression flag to play
This commit is contained in:
John Mair 2013-07-23 17:47:33 -07:00
commit d682b44b40
2 changed files with 41 additions and 1 deletions

View file

@ -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

View file

@ -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