From: Andrea Fazzi Date: 2008-10-13T17:31:52+09:00 Subject: Re: [QUIZ] Modular Arithmetic (#179) 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