Last active
September 24, 2018 13:05
-
-
Save harrisonmalone/159c92e0e41da37f4ff8d915f2002b7a to your computer and use it in GitHub Desktop.
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
| # Goal: Starting with shopping_centre, get back the string '29%' | |
| require 'pry' | |
| squash = { | |
| name: 'squash', | |
| length: 15, | |
| nutrients: [ | |
| { | |
| vitamin: 'A', | |
| daily_percentage: '4%', | |
| }, | |
| { | |
| vitamin: 'C', | |
| daily_percentage: '29%' | |
| } | |
| ] | |
| } | |
| beef = {} | |
| noodles = {} | |
| class Restaurant | |
| attr_accessor :name, :menu | |
| def initialize(name) | |
| @name = name | |
| @menu = [] | |
| end | |
| def add_dish_to_menu(dish) | |
| @menu << dish | |
| end | |
| end | |
| stir_fry = { | |
| price: 13.50, | |
| ingredients: [ | |
| beef, | |
| noodles, | |
| squash | |
| ] | |
| } | |
| mr_wok = Restaurant.new('Mr Wok') | |
| mr_wok.add_dish_to_menu(stir_fry) | |
| shopping_centre = { | |
| address: '5 Somewhere Ln, Blahville', | |
| chinese_restaurant: { | |
| address: 'Lot 4', | |
| details: mr_wok | |
| } | |
| } | |
| binding.pry | |
| p "hello" | |
| # answer | |
| # shopping_centre[:chinese_restaurant][:details].menu[0][:ingredients][2][:nutrients][1][:daily_percentage] => "29%" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment