Freeze `Rational` and `Complex` objects
MODIFY
mrbgems/mruby-complex/src/complex.c
mrbgems/mruby-complex/src/complex.c
@@ -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;
}

MODIFY
mrbgems/mruby-complex/test/complex.rb
mrbgems/mruby-complex/test/complex.rb
@@ -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

MODIFY
mrbgems/mruby-rational/src/rational.c
mrbgems/mruby-rational/src/rational.c
@@ -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;
}

MODIFY
mrbgems/mruby-rational/test/rational.rb
mrbgems/mruby-rational/test/rational.rb
@@ -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

Freeze `Rational` and `Complex` objects