class Context
attr_accessor :strategy
def initialize(strategy)
@strategy = strategy
end
def set_strategy(strategy)
@strategy = strategy
end
def do(obj)
strategy.do(obj)
end
end
def StrategyA
def do(obj)
obj.modify("A")
end
end
def StrategyB
def do(obj)
obj.modify("B")
end
end
class Obj
attr_reader :name
def modify(name)
@name = name
end
def say
puts @name
end
end
context = Context.new(StrategyA.new)
obj = Obj.new
context.do(obj)