diff --git a/lib/pry/extended_commands/experimental.rb b/lib/pry/extended_commands/experimental.rb index d77fff1a..8b01525f 100644 --- a/lib/pry/extended_commands/experimental.rb +++ b/lib/pry/extended_commands/experimental.rb @@ -7,10 +7,43 @@ class Pry output.puts opts[:eval_string] end + command "power" do + instance_eval opts[:ni_arg_string] + end + command "play-string", "Play a string as input" do Pry.active_instance.input = StringIO.new(opts[:arg_string]) end + command "play-method", "Play a method source as input" do |*args| + target = target() + opt = Slop.parse!(args) do |opt| + opt.banner "Usage: play-method [--replay START..END] [--clear] [--grep PATTERN] [--help]\n" + + opt.on :l, :lines, 'The line (or range of lines) to replay.', true, :as => Range + opt.on :h, :help, "This message." do + output.puts opt + end + end + + next if opt.help? + + meth_name = args.shift + if (meth = get_method_object(meth_name, target, {})).nil? + output.puts "Invalid method name: #{meth_name}. Type `play-method --help` for help" + next + end + + code, code_type = code_and_code_type_for(meth) + next if !code + + slice = opt[:l] ? opt[:l] : (0..-1) + + sliced_code = code.each_line.to_a[slice].join("\n") + + Pry.active_instance.input = StringIO.new(sliced_code) + end + end end end