rational.c (mrb_rational_copy): allow copying of rational numbers.
MODIFY
include/mruby/internal.h
include/mruby/internal.h
@@ -95,6 +95,7 @@ mrb_value mrb_rational_add(mrb_state *mrb, mrb_value x, mrb_value y);
mrb_value mrb_rational_sub(mrb_state *mrb, mrb_value x, mrb_value y);
mrb_value mrb_rational_mul(mrb_state *mrb, mrb_value x, mrb_value y);
mrb_value mrb_rational_div(mrb_state *mrb, mrb_value x, mrb_value y);
+void mrb_rational_copy(mrb_state *mrb, mrb_value x, mrb_value y);
#endif
#ifdef MRUBY_PROC_H

MODIFY
mrbgems/mruby-bin-mrbc/tools/mrbc/stub.c
mrbgems/mruby-bin-mrbc/tools/mrbc/stub.c
@@ -65,4 +65,7 @@ mrb_value mrb_rational_to_f(mrb_state *mrb, mrb_value x)
{
return mrb_nil_value();
}
+void mrb_rational_copy(mrb_state *mrb, mrb_value x, mrb_value y)
+{
+}
#endif

MODIFY
mrbgems/mruby-rational/src/rational.c
mrbgems/mruby-rational/src/rational.c
@@ -110,6 +110,15 @@ mrb_rational_new(mrb_state *mrb, mrb_int numerator, mrb_int denominator)
#define rational_new(mrb,n,d) mrb_rational_new(mrb, n, d)
+void
+mrb_rational_copy(mrb_state *mrb, mrb_value x, mrb_value y)
+{
+ struct mrb_rational *p1 = rational_ptr(mrb, x);
+ struct mrb_rational *p2 = rational_ptr(mrb, y);
+ p1->numerator = p2->numerator;
+ p1->denominator = p2->denominator;
+}
+
inline static mrb_int
i_gcd(mrb_int x, mrb_int y)
{

MODIFY
src/class.c
src/class.c
@@ -2742,6 +2742,11 @@ init_copy(mrb_state *mrb, mrb_value dest, mrb_value obj)
mrb_bint_copy(mrb, dest, obj);
break;
#endif
+#ifdef MRB_USE_RATIONAL
+ case MRB_TT_RATIONAL:
+ mrb_rational_copy(mrb, dest, obj);
+ break;
+#endif
default:
break;

rational.c (mrb_rational_copy): allow copying of rational numbers.