Commit fa45cc42 authored by Ukrainskiy Sergey's avatar Ukrainskiy Sergey Committed by Yukihiro "Matz" Matsumoto

Fix dependencies

parent d67d2ae8
...@@ -68,12 +68,6 @@ MRuby::GemBox.new do |conf| ...@@ -68,12 +68,6 @@ MRuby::GemBox.new do |conf|
# Use Enumerator::Lazy class (require mruby-enumerator) # Use Enumerator::Lazy class (require mruby-enumerator)
conf.gem :core => "mruby-enum-lazy" conf.gem :core => "mruby-enum-lazy"
# Use Complex class
# conf.gem :core => "mruby-complex"
# Use Rational class
# conf.gem :core => "mruby-rational"
# Use toplevel object (main) methods extension # Use toplevel object (main) methods extension
conf.gem :core => "mruby-toplevel-ext" conf.gem :core => "mruby-toplevel-ext"
......
...@@ -3,6 +3,7 @@ MRuby::Gem::Specification.new('mruby-complex') do |spec| ...@@ -3,6 +3,7 @@ MRuby::Gem::Specification.new('mruby-complex') do |spec|
spec.author = 'mruby developers' spec.author = 'mruby developers'
spec.summary = 'Complex class' spec.summary = 'Complex class'
spec.add_dependency 'mruby-metaprog', core: 'mruby-metaprog'
spec.add_dependency 'mruby-object-ext', core: 'mruby-object-ext' spec.add_dependency 'mruby-object-ext', core: 'mruby-object-ext'
spec.add_dependency 'mruby-numeric-ext', core: 'mruby-numeric-ext' spec.add_dependency 'mruby-numeric-ext', core: 'mruby-numeric-ext'
spec.add_dependency 'mruby-math', core: 'mruby-math' spec.add_dependency 'mruby-math', core: 'mruby-math'
......
...@@ -3,6 +3,7 @@ MRuby::Gem::Specification.new('mruby-rational') do |spec| ...@@ -3,6 +3,7 @@ MRuby::Gem::Specification.new('mruby-rational') do |spec|
spec.author = 'mruby developers' spec.author = 'mruby developers'
spec.summary = 'Rational class' spec.summary = 'Rational class'
spec.add_dependency 'mruby-metaprog', core: 'mruby-metaprog'
spec.add_dependency 'mruby-object-ext', core: 'mruby-object-ext' spec.add_dependency 'mruby-object-ext', core: 'mruby-object-ext'
spec.add_dependency 'mruby-numeric-ext', core: 'mruby-numeric-ext' spec.add_dependency 'mruby-numeric-ext', core: 'mruby-numeric-ext'
end end
...@@ -10,6 +10,18 @@ class Rational < Numeric ...@@ -10,6 +10,18 @@ class Rational < Numeric
"(#{to_s})" "(#{to_s})"
end end
def to_f
@numerator.to_f / @denominator.to_f
end
def to_i
to_f.to_i
end
def to_r
self
end
def to_s def to_s
"#{numerator}/#{denominator}" "#{numerator}/#{denominator}"
end end
......
...@@ -9,6 +9,21 @@ assert 'Rational' do ...@@ -9,6 +9,21 @@ assert 'Rational' do
assert_equal [r.numerator, r.denominator], [5, 1] assert_equal [r.numerator, r.denominator], [5, 1]
end end
assert 'Rational#to_f' do
assert_float Rational(2).to_f, 2.0
assert_float Rational(9, 4).to_f, 2.25
assert_float Rational(-3, 4).to_f, -0.75
assert_float Rational(20, 3).to_f, 6.666666666666667
end
assert 'Rational#to_i' do
assert_equal Rational(2, 3).to_i, 0
assert_equal Rational(3).to_i, 3
assert_equal Rational(300.6).to_i, 300
assert_equal Rational(98, 71).to_i, 1
assert_equal Rational(-30, 2).to_i, -15
end
assert 'Rational#*' do assert 'Rational#*' do
assert_rational Rational(2, 3) * Rational(2, 3), Rational(4, 9) assert_rational Rational(2, 3) * Rational(2, 3), Rational(4, 9)
assert_rational Rational(900) * Rational(1), Rational(900, 1) assert_rational Rational(900) * Rational(1), Rational(900, 1)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment