Forked from RiverGlide/dynamic_role_switching_spec.rb
Created
March 19, 2011 13:07
-
-
Save antonymarcano/877467 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$:.unshift(File.dirname(__FILE__), ".") | |
require 'rubygems' | |
require 'rspec' | |
module Butler | |
def put_fork_on_the_left_of place | |
place.unshift "fork" | |
place | |
end | |
def put_knife_on_the_right_of place | |
place.push "knife" | |
place | |
end | |
end | |
module LayTable | |
def follow_instructions | |
place = [] | |
put_fork_on_the_left_of place | |
put_knife_on_the_right_of place | |
end | |
end | |
class MyActor | |
#decide how we will make the actor know in which role they should perform the task | |
def initialize role | |
extend role | |
end | |
def perform task | |
recall_how_to_do task | |
follow_instructions | |
end | |
private | |
def recall_how_to_do something | |
extend something | |
end | |
end | |
describe "Something" do | |
it "Something" do | |
butler = MyActor.new Butler | |
butler.perform(LayTable).should == ["fork","knife"] | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This approach removes the need for too much knowledge of what's being operated on.
If some value needs to be remembered for later use we should ask the actor to take_note_of key,value to save any information that will later need to be recalled... It can then be explicitly recalled by subsequent tasks