Hi , I have these three lines of code. The first 2 run perfectly, when I
add the 3rd line, it says:
initialize': undefined method description’ for #Mocha:0x85e8dfc
(NoMethodError)
from Espresso.rb:43:in new' from Espresso.rb:43:in ’
I would invite you to try our new library called Jackbox. In it we toy
with the ideas of closures as modules / ruby code Injectors. You can
install it by doing: gem install jackbox.
With it you would do the following:
class Beverage
attr_accessor :cost
attr_accessor :description
def initialize @description = “unknown beverage” @cost = 1.20
end
end
class Decaf < Beverage
def initialize @description = “decaf”
end
def cost
1.50
end
end
injector :mocha do
def cost
super + 0.20
end
def description @description = super + ’ mocha’
end
end
injector :half_n_half do
def cost
super + 0.10
end
def description @description = super + ’ creamer’
end
end
It toys with the ideas of closures as modules. In it you’ll find a
series of new takes on ruby that are sure to spike you interest. With
it we have come up with a solution to the decorators handicap in ruby
and introduced some new constructs for code injection.
Please feel free to use it free of charge and to send us your comments
or inquiries. Available from RubyGems.org for Linux, Mac, and Windows.
Just run: gem install jackbox.
Thank you.
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.