Hi,
I realized that Modulo#modularize contains a lot of useless conditionals.
Here below a refactored revision of my solution. Check
http://github.com/remogatto/quizzes/tree/master/179/lib/modulo.rb
for better formatting.
class Modulo
include Comparable
[:+, :-, :*].each do |meth|
define_method(meth) { |other_n| Modulo.new(@n.send(meth, other_n.to_i), @m) }
end
def initialize(n = 0, m = 26)
@n, @m = n % m, m
end
def <=>(other_n)
@n <=> other_n.to_i
end
def to_i
@n
end
private
def coerce(numeric)
[@n, numeric]
end
end
Regards,
Andrea