Sha256: 78fd42666aaf311eeb264e10101dc9c437572928aaf344772e5c5eb5e80ec75c
Contents?: true
Size: 1.32 KB
Versions: 1
Compression:
Stored size: 1.32 KB
Contents
class Recipe attr_accessor :name, :ingredients, :instructions def initialize(name, &block) self.name = name self.ingredients = [] self.instructions = [] instance_eval &block end def to_s output << "EORECIPE #{name} #{'=' * name.size} Ingredients: #{ingredients.join(', ')} #{ out = "" instructions.each_with_index do |instruction, index| out << "#{index + 1}) #{instruction}\n" end out } EORECIPE" end def ingredient(name, options = {}) ingredient = name ingredient << " (#{options[:amount]})" if options[:amount] ingredients << ingredient end def step(text, options = {}) instruction = text instruction << " (#{options[:for]})" if options[:for] instructions << instruction end def amount :amount end def during :for end end puts Recipe.new("Noodles and Cheese") { ingredient "Water", amount => "2 cups" ingredient "Noodles", amount => "1 cup" ingredient "Cheese", amount => "1/2 cup" step "Heat water to boiling.", during => "5 minutes" step "Add noodles to boiling water.", during => "6 minutes" step "Drain water." step "Mix cheese in with noodles." }
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
menualu0100782851-0.1.1 | lib/prct11/prueba.rb |