Ruby - Modules and Mixins
Identify the error in this Ruby code using Comparable:
class Item
include Comparable
attr_reader :weight
def initialize(weight)
@weight = weight
end
def compare(other)
weight <=> other.weight
end
endIdentify the error in this Ruby code using Comparable:
class Item
include Comparable
attr_reader :weight
def initialize(weight)
@weight = weight
end
def compare(other)
weight <=> other.weight
end
end<=>, not compare.attr_reader and include are correct.<=>, not compare -> Option D<=> method for Comparable [OK]<=> for Comparable [OK]compareinclude and extendattr_writer is needed here15+ quiz questions · All difficulty levels · Free
Free Signup - Practice All Questions