Skip to content

Instantly share code, notes, and snippets.

@esmevane
Created March 24, 2014 14:42
Show Gist options
  • Select an option

  • Save esmevane/9741431 to your computer and use it in GitHub Desktop.

Select an option

Save esmevane/9741431 to your computer and use it in GitHub Desktop.
[ Ruby ] Make a burrito
class Burrito
attr_reader :fillings
def initialize(*fillings)
@fillings = fillings
end
def to_hash
{ burrito: { filling: fillings.map(&:to_s) } }
end
end
class Chicken
def to_s
"delicious chicken"
end
end
class Cheese
def to_s
"mild cheddar"
end
end
class Beans
def to_s
"black beans"
end
end
class Rice
def to_s
"brown rice & cilantro"
end
end
burrito = Burrito.new(Chicken.new, Cheese.new, Beans.new, Rice.new)
puts burrito.to_hash
@stormcry
Copy link
Copy Markdown

{:burrito=>{:filling=>["delicious chicken", "mild cheddar", "black beans", "brown rice & cilantro"]}}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment