Created
December 6, 2011 18:00
-
-
Save remogatto/1439190 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
[numeric, @n] | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment