Complete the code to include the Comparable module in the class.
class Box include [1] end
The Comparable module must be included to enable comparison operators.
Complete the code to define the <=> method for comparing boxes by volume.
class Box include Comparable def initialize(length, width, height) @length = length @width = width @height = height end def volume @length * @width * @height end def [1](other) volume <=> other.volume end end
The <=> method is the spaceship operator used by Comparable to compare objects.
Fix the error in the comparison method name to enable Comparable functionality.
class Box include Comparable def initialize(size) @size = size end def [1](other) @size <=> other.size end protected attr_reader :size end
The method must be named <=> for Comparable to work correctly.
Fill both blanks to create a hash mapping box volumes to their sizes, filtering volumes greater than 100.
boxes = [Box.new(2, 3, 4), Box.new(5, 5, 5), Box.new(1, 1, 1)] volume_map = {box.[1] => box.[2] for box in boxes if box.volume > 100}
The hash keys are volumes and values are sizes, filtered by volume > 100.
Fill all three blanks to create a hash of box sizes to volumes, including only boxes with volume less than 50.
boxes = [Box.new(1, 2, 3), Box.new(2, 2, 2), Box.new(3, 3, 3)] result = {box.[1] => box.[2] for box in boxes if box.volume [3] 50}
The hash maps sizes to volumes for boxes with volume less than 50.