Pair
, as follows:
Pair
is constructed with two values, both assumed to have a size
method.
eqsize
method returns true iff the size
of both values is the same.
to_s
method returns a string with the two sizes. Ex: "3 / 4"
.
>> p = Pair.new("abc", [1,2,3]) >> p.eqsize => true >> p.to_s => "3 / 3" >> Pair.new([], {1=>2}).to_s => "0 / 1"
EC ½ point: Tell me something about writing classes in Ruby not evidenced above.
EC ½ point: Provide Pair
with "getters" a
and b
, to fetch the two values held.
Pair
.
class Pair def initialize(a,b) @a,@b = a,b end def eqsize @a.size == @b.size end def to_s "#{@a.size} / #{@b.size}" end attr_reader :a, :b endEC ½ point: Tell me something about writing classes in Ruby not evidenced above.
@@
Pair
with "getters" a
and b
, to fetch the two values held.
attr_reader
.