Skip to content

Commit

Permalink
Allow passing of arguments to wend methods
Browse files Browse the repository at this point in the history
  • Loading branch information
Russell Dunphy committed Dec 7, 2012
1 parent 6628c36 commit fac46da
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
7 changes: 4 additions & 3 deletions lib/wendy.rb
Expand Up @@ -6,13 +6,14 @@ def wend(arg)

class Wender

def initialize(initiator, arg)
def initialize(initiator, arg, *others)
@initiator = initiator
@arg = arg
@others = others
end

def through(method)
Wender.new(initiator, initiator.send(method, arg))
def through(method, *others)
Wender.new(initiator, initiator.send(method, *([arg] + others)))
end

def result
Expand Down
16 changes: 15 additions & 1 deletion spec/lib/wendy_spec.rb
Expand Up @@ -11,16 +11,30 @@ def double(x)
x + x
end

def add(x, y)
x + y
end

def wend_test
wend(5).through(:square).and(:double).and_return
end

def wend_test_with_arg
wend(5).through(:square).and(:double).and(:add, 15).and_return
end

end

describe Wendy do

let(:wender) { TestWender.new }

it 'allows method chaining' do
TestWender.new.wend_test.should eq 50
wender.wend_test.should eq 50
end

it 'passes additional arguments to methods in the chain' do
wender.wend_test_with_arg.should eq 65
end

end
Binary file added wendy-0.0.1.gem
Binary file not shown.

0 comments on commit fac46da

Please sign in to comment.