summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Mair <jrmair@gmail.com>2012-02-27 13:19:20 +1300
committerJohn Mair <jrmair@gmail.com>2012-02-27 13:19:20 +1300
commite0525bcef306beca092247f8571179232397ca15 (patch)
tree4edb066dd3e1be8f3ea39bc25e6479dc716eaa08
parentce920efd66505136db1d3f694f9ca6888c63f518 (diff)
downloadpry-feature/explicit_block.tar.gz
accessing blocks in commands via &blockfeature/explicit_block
e.g command "my-command", "desc", :takes_block => true do |&block| block.call end * Due to a broken ruby 1.8 Proc#arity (i.e proc { |x, y, &block| }.arity #=> 1) we can't use explicit &block arguments :( Just storing it here as a testament to its beauty and elegance * "On a flower of dark sobs and waters, you left me" -- ghazal of the unborn child, garcia lorca
-rw-r--r--lib/pry/command.rb2
-rw-r--r--lib/pry/command_set.rb2
-rw-r--r--test/test_command.rb20
3 files changed, 12 insertions, 12 deletions
diff --git a/lib/pry/command.rb b/lib/pry/command.rb
index 09829c59..ca46f4c2 100644
--- a/lib/pry/command.rb
+++ b/lib/pry/command.rb
@@ -420,7 +420,7 @@ class Pry
begin
dummy(*correct_arg_arity(block.arity, args), &command_block)
rescue ArgumentError => ex
- if ex.message =~ /1 for 0/
+ if ex.backtrace.first =~ /dummy/ && ex.message =~ /1 for 0/
dummy(&command_block)
else
raise
diff --git a/lib/pry/command_set.rb b/lib/pry/command_set.rb
index 74a34b4d..6170c435 100644
--- a/lib/pry/command_set.rb
+++ b/lib/pry/command_set.rb
@@ -337,7 +337,7 @@ class Pry
:shellwords => true,
:listing => name,
:use_prefix => true,
- :takes_block => true
+ :takes_block => false
}
end
diff --git a/test/test_command.rb b/test/test_command.rb
index f453ee3f..2e21c578 100644
--- a/test/test_command.rb
+++ b/test/test_command.rb
@@ -345,7 +345,7 @@ describe "Pry::Command" do
describe "block parameters" do
before do
@context = Object.new
- @set.command "walking-spanish", "down the hall" do |&block|
+ @set.command "walking-spanish", "down the hall", :takes_block => true do |&block|
inject_var(:@x, block.call, target)
end
@set.import Pry::Commands
@@ -392,7 +392,7 @@ describe "Pry::Command" do
describe "arg_string" do
it 'should remove block-related content from arg_string (with one normal arg)' do
- @set.block_command "walking-spanish", "down the hall" do |x, y|
+ @set.block_command "walking-spanish", "down the hall", :takes_block => true do |x, y|
inject_var(:@arg_string, arg_string, target)
inject_var(:@x, x, target)
end
@@ -404,7 +404,7 @@ describe "Pry::Command" do
end
it 'should remove block-related content from arg_string (with no normal args)' do
- @set.block_command "walking-spanish", "down the hall" do
+ @set.block_command "walking-spanish", "down the hall", :takes_block => true do
inject_var(:@arg_string, arg_string, target)
end
redirect_pry_io(InputTester.new("walking-spanish | { :jesus }",
@@ -430,7 +430,7 @@ describe "Pry::Command" do
describe "args" do
describe "block_command" do
it "should remove block-related content from arguments" do
- @set.block_command "walking-spanish", "glass is full of sand" do |x, y|
+ @set.block_command "walking-spanish", "glass is full of sand", :takes_block => true do |x, y|
inject_var(:@x, x, target)
inject_var(:@y, y, target)
end
@@ -458,7 +458,7 @@ describe "Pry::Command" do
describe "create_command" do
it "should remove block-related content from arguments" do
- @set.create_command "walking-spanish", "punk sanders carved one out of wood" do
+ @set.create_command "walking-spanish", "punk sanders carved one out of wood", :takes_block => true do
def process(x, y)
inject_var(:@x, x, target)
inject_var(:@y, y, target)
@@ -493,7 +493,7 @@ describe "Pry::Command" do
describe "blocks can take parameters" do
describe "{} style blocks" do
it 'should accept multiple parameters' do
- @set.block_command "walking-spanish", "down the hall" do |&block|
+ @set.block_command "walking-spanish", "down the hall", :takes_block => true do |&block|
inject_var(:@x, block.call(1, 2), target)
end
@@ -507,7 +507,7 @@ describe "Pry::Command" do
describe "do/end style blocks" do
it 'should accept multiple parameters' do
- @set.create_command "walking-spanish", "litella" do
+ @set.create_command "walking-spanish", "litella", :takes_block => true do
def process(&block)
inject_var(:@x, block.call(1, 2), target)
end
@@ -538,7 +538,7 @@ describe "Pry::Command" do
describe "exposing block parameter" do
describe "block_command" do
it "should expose block in command_block method" do
- @set.block_command "walking-spanish", "glass full of sand" do
+ @set.block_command "walking-spanish", "glass full of sand", :takes_block => true do
inject_var(:@x, command_block.call, target)
end
redirect_pry_io(InputTester.new("walking-spanish | { :jesus }",
@@ -553,7 +553,7 @@ describe "Pry::Command" do
describe "create_command" do
it "should expose &block in create_command's process method" do
- @set.create_command "walking-spanish", "down the hall" do
+ @set.create_command "walking-spanish", "down the hall", :takes_block => true do
def process(&block)
inject_var(:@x, block.call, target)
end
@@ -566,7 +566,7 @@ describe "Pry::Command" do
end
it "should expose block in command_block method" do
- @set.create_command "walking-spanish", "homemade special" do
+ @set.create_command "walking-spanish", "homemade special", :takes_block => true do
def process
inject_var(:@x, command_block.call, target)
end