Decorators in Scale

12 views
Skip to first unread message

Lou Henry Alvarez

unread,
Sep 21, 2015, 3:29:54 PM9/21/15
to rubyonra...@googlegroups.com
# 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/.
Reply all
Reply to author
Forward
0 new messages