Skip to content

Commit

Permalink
Improve Numeric#is_a? with Integer.=== and Float.===
Browse files Browse the repository at this point in the history
  • Loading branch information
meh committed Oct 18, 2013
1 parent 56879e0 commit 3708a01
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions corelib/numeric.rb
Expand Up @@ -141,6 +141,13 @@ def integer?
`#{self} % 1 === 0`
end

def is_a?(klass)
return true if klass == Float && Float === self
return true if klass == Integer && Integer === self

super
end

alias magnitude abs

alias modulo %
Expand Down Expand Up @@ -275,12 +282,12 @@ def infinite?

class Integer < Numeric
def self.===(other)
other.is_a?(Numeric) && `(other % 1) == 0`
`other._isNumber && (other % 1) == 0`
end
end

class Float < Numeric
def self.===(other)
other.is_a?(Numeric) && `(other % 1) != 0`
`other._isNumber && (other % 1) != 0`
end
end

0 comments on commit 3708a01

Please sign in to comment.