diff options
author | mrkn <mrkn@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2016-03-18 14:52:46 +0000 |
---|---|---|
committer | mrkn <mrkn@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2016-03-18 14:52:46 +0000 |
commit | 5757e531afd2a26b1c6bb78ead972f7e430ebac3 (patch) | |
tree | 2a8ada9bacf0c11edb940a2729e708f8b6fa624b /ext | |
parent | de1b82192b0082f55e8927dc1821892622e73a85 (diff) | |
download | ruby-5757e531afd2a26b1c6bb78ead972f7e430ebac3.tar.gz |
* numeric.c (int_to_f, fix_to_f): rename fix_to_f to int_to_f, and add
treatment for subclasses which don't have definitions of to_f method.
* numeric.c (Integer#to_f, Fixnum#to_f): move to_f method from Fixnum
to Integer.
* ext/-test-/integer/my_integer.rb: define helper class for testing
to_f method for a subclass of Integer.
* ext/-test-/integer/extconf.rb: ditto.
* ext/-test-/integer/init.c: ditto.
* test/-ext-/integer/test_my_integer.rb: examine to_f method for a
subclass of Integer.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54179 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext')
-rw-r--r-- | ext/-test-/integer/extconf.rb | 8 | ||||
-rw-r--r-- | ext/-test-/integer/init.c | 11 | ||||
-rw-r--r-- | ext/-test-/integer/my_integer.c | 16 |
3 files changed, 35 insertions, 0 deletions
diff --git a/ext/-test-/integer/extconf.rb b/ext/-test-/integer/extconf.rb new file mode 100644 index 0000000000..20bfffbec2 --- /dev/null +++ b/ext/-test-/integer/extconf.rb @@ -0,0 +1,8 @@ +# frozen_string_literal: false +$INCFLAGS << " -I$(topdir) -I$(top_srcdir)" +$srcs = Dir[File.join($srcdir, "*.{#{SRC_EXT.join(%q{,})}}")] +inits = $srcs.map {|s| File.basename(s, ".*")} +inits.delete("init") +inits.map! {|s|"X(#{s})"} +$defs << "-DTEST_INIT_FUNCS(X)=\"#{inits.join(' ')}\"" +create_makefile("-test-/integer") diff --git a/ext/-test-/integer/init.c b/ext/-test-/integer/init.c new file mode 100644 index 0000000000..fc256ea16b --- /dev/null +++ b/ext/-test-/integer/init.c @@ -0,0 +1,11 @@ +#include "ruby.h" + +#define init(n) {void Init_##n(VALUE klass); Init_##n(klass);} + +void +Init_integer(void) +{ + VALUE mBug = rb_define_module("Bug"); + VALUE klass = rb_define_class_under(mBug, "Integer", rb_cObject); + TEST_INIT_FUNCS(init); +} diff --git a/ext/-test-/integer/my_integer.c b/ext/-test-/integer/my_integer.c new file mode 100644 index 0000000000..d86474bd7d --- /dev/null +++ b/ext/-test-/integer/my_integer.c @@ -0,0 +1,16 @@ +#include "ruby.h" + +static VALUE +my_integer_s_new(VALUE klass) +{ + return Data_Wrap_Struct(klass, 0, 0, 0); +} + +void +Init_my_integer(VALUE klass) +{ + VALUE cMyInteger; + + cMyInteger = rb_define_class_under(klass, "MyInteger", rb_cInteger); + rb_define_singleton_method(cMyInteger, "new", my_integer_s_new, 0); +} |