Created
March 24, 2014 14:42
-
-
Save esmevane/9741431 to your computer and use it in GitHub Desktop.
[ Ruby ] Make a burrito
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
{:burrito=>{:filling=>["delicious chicken", "mild cheddar", "black beans", "brown rice & cilantro"]}}