Class: Menu
Instance Attribute Summary collapse
-
#dishes ⇒ Object
readonly
Returns the value of attribute dishes.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#prices ⇒ Object
readonly
Returns the value of attribute prices.
Instance Method Summary collapse
-
#<=>(other) ⇒ Object
—- sobrecargas —.
-
#initialize(name, dishes, prices) ⇒ Menu
constructor
A new instance of Menu.
Constructor Details
#initialize(name, dishes, prices) ⇒ Menu
Returns a new instance of Menu.
13 14 15 16 |
# File 'lib/Menu.rb', line 13 def initialize (name, dishes, prices) @name = name @dishes, @prices = dishes, prices end |
Instance Attribute Details
#dishes ⇒ Object (readonly)
Returns the value of attribute dishes.
11 12 13 |
# File 'lib/Menu.rb', line 11 def dishes @dishes end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
11 12 13 |
# File 'lib/Menu.rb', line 11 def name @name end |
#prices ⇒ Object (readonly)
Returns the value of attribute prices.
11 12 13 |
# File 'lib/Menu.rb', line 11 def prices @prices end |
Instance Method Details
#<=>(other) ⇒ Object
—- sobrecargas —
20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/Menu.rb', line 20 def <=>(other) return nil unless other.instance_of? Menu total_impact = 0 total_price = 0 other_impact = 0 other_price = 0 dishes.each { | dish | total_impact += (dish.terrainTotal + dish.dailygei) } other.dishes.each { | dish | other_impact += (dish.terrainTotal + dish.dailygei) } prices.each { | price | total_price += price } other.prices.each { | price | other_price += price } total_impact + total_price <=> other_impact + other_price end |