Skip to content

Instantly share code, notes, and snippets.

Revisions

  1. James Martin revised this gist Mar 19, 2011. 1 changed file with 1 addition and 2 deletions.
    3 changes: 1 addition & 2 deletions dynamic_role_switching_spec.rb
    Original file line number Diff line number Diff line change
    @@ -4,7 +4,7 @@
    module Butler

    def self.included base
    base.send :attr_accessor, :place
    base.instance_eval { @place = [] }
    end

    def put_fork_on_the_left
    @@ -53,7 +53,6 @@ class MyActor
    #Todo: decide how we will make the actor know in which role they should perform the task
    def initialize role
    extend role
    @place = [] #figure out how to initialize this in the role
    end

    def perform task
  2. @RiverGlide RiverGlide revised this gist Mar 18, 2011. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions dynamic_role_switching_spec.rb
    Original file line number Diff line number Diff line change
    @@ -35,15 +35,15 @@ def place_boil_in_bag_into_pot
    end

    module MakeDinner
    def instructions
    def follow_instructions
    turn_on_stove
    boil_water
    place_boil_in_bag_into_pot
    end
    end

    module LayTable
    def instructions
    def follow_instructions
    put_fork_on_the_left
    put_knife_on_the_right
    end
    @@ -58,7 +58,7 @@ def initialize role

    def perform task
    recall_how_to_do task
    instructions
    follow_instructions
    end

    private
  3. @RiverGlide RiverGlide revised this gist Mar 18, 2011. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions dynamic_role_switching_spec.rb
    Original file line number Diff line number Diff line change
    @@ -19,7 +19,7 @@ def put_knife_on_the_right
    end

    module Cook
    #Do something similar here
    #Todo: Do something similar here

    def boil_water

    @@ -50,7 +50,7 @@ def instructions
    end

    class MyActor
    #decide how we will make the actor know in which role they should perform the task
    #Todo: decide how we will make the actor know in which role they should perform the task
    def initialize role
    extend role
    @place = [] #figure out how to initialize this in the role
  4. @RiverGlide RiverGlide created this gist Mar 18, 2011.
    77 changes: 77 additions & 0 deletions dynamic_role_switching_spec.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,77 @@
    $:.unshift(File.dirname(__FILE__), ".")
    require 'spec_helper'

    module Butler

    def self.included base
    base.send :attr_accessor, :place
    end

    def put_fork_on_the_left
    @place.unshift "fork"
    @place
    end

    def put_knife_on_the_right
    @place.push "knife"
    @place
    end
    end

    module Cook
    #Do something similar here

    def boil_water

    end

    def turn_on_stove

    end

    def place_boil_in_bag_into_pot

    end
    end

    module MakeDinner
    def instructions
    turn_on_stove
    boil_water
    place_boil_in_bag_into_pot
    end
    end

    module LayTable
    def instructions
    put_fork_on_the_left
    put_knife_on_the_right
    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
    @place = [] #figure out how to initialize this in the role
    end

    def perform task
    recall_how_to_do task
    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