Yes, what you are looking at here is a code sample of what is possible
with Jackbox closures. You see normally decorators in ruby either suffer
from class identity loss or limit the times they can be applied to an
object to 1(one) time.
Here a a couple of articles on that:
So with our closures you can apply the same pattern to an object over
cup = Coffee.new.enrich milk, sprinkles, sprinkles
but the instance remains being what it is.
What's more you can have the class introspect on the decorators it
cup.injectors.should == [:milk, :sprinkles, :sprinkles ]
Furthermore you can add new facets to your decorators:
user_input = 'extra red sprinkles'
define_method :appearance do
cup.appearance.should == 'extra red sprinkles'
cup.cost.should == 2.25
And then latter:
user_input = 'cold milk'
define_method :temp do
cup.temp.should == 'cold'
cup.cost.should == 2.55
Decorators are useful in graphical environments including HTML, in steam
processing, command processors to name a few.
Thank you, kindly.