diff options
| author | Yukihiro "Matz" Matsumoto <[email protected]> | 2019-05-29 11:46:42 +0900 |
|---|---|---|
| committer | GitHub <[email protected]> | 2019-05-29 11:46:42 +0900 |
| commit | a1e1af44d205c2c29608f508cce84d6b6ebd2bbf (patch) | |
| tree | 3d24ba8e839a8947c3efe19b23e49590a99a2f1f /mrbgems/mruby-rational/mrblib | |
| parent | 4b82fdb637ac653dbc6ac6c222abac17c62608ae (diff) | |
| parent | 902b2ce3c669d4e3b5c20b2c90a3b3982f17d820 (diff) | |
| download | mruby-a1e1af44d205c2c29608f508cce84d6b6ebd2bbf.tar.gz mruby-a1e1af44d205c2c29608f508cce84d6b6ebd2bbf.zip | |
Merge pull request #4475 from shuujii/fix-Rational-eq-Complex
Fix `Rational#==(Complex)`
Diffstat (limited to 'mrbgems/mruby-rational/mrblib')
| -rw-r--r-- | mrbgems/mruby-rational/mrblib/rational.rb | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/mrbgems/mruby-rational/mrblib/rational.rb b/mrbgems/mruby-rational/mrblib/rational.rb index 4936b1123..54d9a955f 100644 --- a/mrbgems/mruby-rational/mrblib/rational.rb +++ b/mrbgems/mruby-rational/mrblib/rational.rb @@ -62,6 +62,19 @@ class Rational < Numeric nil end end + + def ==(rhs) + if rhs.is_a?(Integral) + return numerator == rhs if denominator == 1 + rhs = Rational(rhs) + end + + if rhs.is_a?(Rational) + numerator * rhs.denominator == denominator * rhs.numerator + else + rhs == self + end + end end class Numeric |
