Commit 48903850 authored by KOBAYASHI Shuji's avatar KOBAYASHI Shuji

Freeze `Rational` and `Complex` objects

parent 5f4eb877
......@@ -24,6 +24,7 @@ complex_new(mrb_state *mrb, mrb_float real, mrb_float imaginary)
struct mrb_complex *p = complex_ptr(mrb, comp);
p->real = real;
p->imaginary = imaginary;
MRB_SET_FROZEN_FLAG(s);
return comp;
}
......
def assert_complex(real, exp)
assert_float real.real, exp.real
assert_float real.real, exp.real
assert_float real.imaginary, exp.imaginary
end
......@@ -126,3 +126,9 @@ assert 'Complex::to_i' do
Complex(1, 2).to_i
end
end
assert 'Complex#frozen?' do
assert_predicate(1i, :frozen?)
assert_predicate(Complex(2,3), :frozen?)
assert_predicate(4+5i, :frozen?)
end
......@@ -37,6 +37,7 @@ rational_new(mrb_state *mrb, mrb_int numerator, mrb_int denominator)
struct mrb_rational *p = rational_ptr(rat);
p->numerator = numerator;
p->denominator = denominator;
MRB_SET_FROZEN_FLAG(s);
return rat;
}
......
......@@ -278,3 +278,9 @@ assert 'Rational#negative?' do
assert_not_predicate(Rational(2,3), :negative?)
assert_not_predicate(Rational(0), :negative?)
end
assert 'Rational#frozen?' do
assert_predicate(1r, :frozen?)
assert_predicate(Rational(2,3), :frozen?)
assert_predicate(4/5r, :frozen?)
end
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