Permalink
Browse files

The command is the first arg. There is no need for the fancy range

  • Loading branch information...
1 parent 9071c18 commit d6c0128a151d8f521823facccae5cad4b682cf50 @bmizerany committed Aug 18, 2008
Showing with 5 additions and 16 deletions.
  1. +4 −15 lib/frylock.rb
  2. +1 −1 test/command_test.rb
View
19 lib/frylock.rb
@@ -21,25 +21,14 @@ def run=(v)
class Command
def initialize(cmd, &b)
- @cmd = case cmd
- when Symbol
- cmd = cmd.to_s
- else
- cmd
- end
+ @cmd = cmd
+ @cmd = cmd.to_s if cmd.kind_of?(Symbol)
@b = b
end
def call(argv)
- found = false
- argv.each_with_index { |a,i| found = i and break if @cmd === a }
- if found
- range = if @b.arity > 0
- (found + 1)..(found + @b.arity)
- else
- found + 1
- end
- @b.call(*argv[range])
+ if @cmd === argv[0] && (@b.arity == -1 || argv.size - 1 == @b.arity)
+ @b.call(*argv[1..-1])
end
end
end
View
2 test/command_test.rb
@@ -22,7 +22,7 @@ def test_command(cmd, argv, &b)
specify "should know only send params needed by block" do
@mock.expects(:called).with('bar')
- test_command(:foo, ['foo', 'bar', 'baz']) { |a| @mock.called(a) }
+ test_command(:foo, ['foo', 'bar']) { |a| @mock.called(a) }
end
specify "should know only send params needed by block 2" do

0 comments on commit d6c0128

Please sign in to comment.