# our class (can be anything..., think rendering, or stream processing)
class Coffee
def cost
1.50
end
end
# our decorators
jack :milk do
def cost
super() + 0.30
end
end
jack :vanilla do
def cost
super() + 0.15
end
end
# the coffee
cup = Coffee.new.enrich(milk, vanilla, vanilla) # this list can....
# our tests
cup.cost.should == 2.10
cup.injectors.sym_list.should == [:milk, :vanilla, :vanilla]
# coffee is coffee
cup.should be_instance_of(Coffee)
For more info check out:
http://blog.jackbox.us/2015/09/decorators-in-scale.html
--
Posted via http://www.ruby-forum.com/.
--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/8d21659c2e1f29f422e822c001a60bfc%40ruby-forum.com.
For more options, visit https://groups.google.com/d/optout.
No comments:
Post a Comment