Guest User

Untitled

a guest
Sep 24th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 KB | None | 0 0
  1. # Goal: Starting with shopping_centre, get back the string '29%'
  2.  
  3. require 'pry'
  4.  
  5. squash = {
  6. name: 'squash',
  7. length: 15,
  8. nutrients: [
  9. {
  10. vitamin: 'A',
  11. daily_percentage: '4%',
  12. },
  13. {
  14. vitamin: 'C',
  15. daily_percentage: '29%'
  16. }
  17. ]
  18. }
  19.  
  20. beef = {}
  21. noodles = {}
  22.  
  23. class Restaurant
  24. attr_accessor :name, :menu
  25. def initialize(name)
  26. @name = name
  27. @menu = []
  28. end
  29. def add_dish_to_menu(dish)
  30. @menu << dish
  31. end
  32. end
  33.  
  34. stir_fry = {
  35. price: 13.50,
  36. ingredients: [
  37. beef,
  38. noodles,
  39. squash
  40. ]
  41. }
  42.  
  43. mr_wok = Restaurant.new('Mr Wok')
  44. mr_wok.add_dish_to_menu(stir_fry)
  45.  
  46. shopping_centre = {
  47. address: '5 Somewhere Ln, Blahville',
  48. chinese_restaurant: {
  49. address: 'Lot 4',
  50. details: mr_wok
  51. }
  52. }
  53.  
  54. binding.pry
  55.  
  56. p "hello"
  57.  
  58. #answer
  59. # shopping_centre[:chinese_restaurant][:details].menu[0][:ingredients][2][:nutrients][1][:daily_percentage] => "29%"
Add Comment
Please, Sign In to add comment