Skip to content

Commit

Permalink
A consequence can now be converted to a Proc that will run the approp…
Browse files Browse the repository at this point in the history
…riate method with the given arguments
  • Loading branch information
jferris committed Dec 3, 2008
1 parent b24c873 commit 714388d
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lib/adherence/consequence.rb
Expand Up @@ -6,6 +6,14 @@ def initialize(options)
assert_valid_options!(options)
end

def to_proc
method = self.method
args = self.args
lambda do
send(method, *args)
end
end

private

def assert_valid_options!(options) #:nodoc:
Expand Down
20 changes: 20 additions & 0 deletions spec/adherence/consequence_spec.rb
Expand Up @@ -42,4 +42,24 @@ def create_consequence
end
end
end

describe Consequence do
before do
@args = [:one, :two]
@consequence = Consequence.new(:method => :example, :args => @args)
end

it "should call its method with the given args when run" do
klass = Class.new
klass.class_eval do
attr_accessor :args
def example(*args)
@args = args
end
end
object = klass.new
object.instance_eval(&@consequence)
object.args.should == @args
end
end
end

0 comments on commit 714388d

Please sign in to comment.