Advertisement
Guest User

Untitled

a guest
Sep 19th, 2019
217
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1. # Goal: Starting with shopping_centre, get back the string '29%'
  2.  
  3. require 'pry'
  4. # To use pry:
  5. # 1. > gem install pry
  6. # 2. Uncomment line 3 (require 'pry')
  7. # 3. Uncomment line 58 (binding.pry)
  8.  
  9. squash = {
  10. name: 'squash',
  11. length: 15,
  12. nutrients: [
  13. {
  14. vitamin: 'A',
  15. daily_percentage: '4%',
  16. },
  17. {
  18. vitamin: 'C',
  19. daily_percentage: '29%'
  20. }
  21. ]
  22. }
  23.  
  24. beef = {}
  25. noodles = {}
  26.  
  27. class Restaurant
  28. attr_accessor :name, :menu
  29. def initialize(name)
  30. @name = name
  31. @menu = []
  32. end
  33. def add_dish_to_menu(dish)
  34. @menu << dish
  35. end
  36. end
  37.  
  38. stir_fry = {
  39. price: 13.50,
  40. ingredients: [
  41. beef,
  42. noodles,
  43. squash
  44. ]
  45. }
  46.  
  47. mr_wok = Restaurant.new('Mr Wok')
  48. mr_wok.add_dish_to_menu(stir_fry)
  49.  
  50. shopping_centre = {
  51. address: '5 Somewhere Ln, Blahville',
  52. chinese_restaurant: {
  53. address: 'Lot 4',
  54. details: mr_wok
  55. }
  56. }
  57.  
  58. #binding.pry
  59.  
  60. #puts 'Your code will stop here. Now type the variable shopping_centre. You can then access values in the shopping_centre hash. Carefully read the code related to the class and instance variables.'
  61.  
  62. print shopping_centre[:chinese_restaurant][:details].menu[0][:ingredients][2][:nutrients][1][:daily_percentage]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement