Merge pull request #4463 from shuujii/freeze-Rational-and-Complex-objects

Freeze `Rational` and `Complex` objects
This commit is contained in:
Yukihiro "Matz" Matsumoto
2019-05-23 19:54:45 +09:00
committed by GitHub
4 changed files with 15 additions and 1 deletions
+1
View File
@@ -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;
}
+7 -1
View File
@@ -1,5 +1,5 @@
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
+1
View File
@@ -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;
}
+6
View File
@@ -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