From b60a7b43feaed02089c158faf0bf647327ed61f0 Mon Sep 17 00:00:00 2001 From: mrkn Date: Fri, 18 Mar 2016 14:52:46 +0000 Subject: * 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 --- test/-ext-/integer/test_my_integer.rb | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 test/-ext-/integer/test_my_integer.rb (limited to 'test/-ext-/integer') diff --git a/test/-ext-/integer/test_my_integer.rb b/test/-ext-/integer/test_my_integer.rb new file mode 100644 index 0000000000..bc4757f463 --- /dev/null +++ b/test/-ext-/integer/test_my_integer.rb @@ -0,0 +1,26 @@ +# frozen_string_literal: false +require 'test/unit' +require "-test-/integer" + +class TestIntegerExt < Test::Unit::TestCase + def test_my_integer_to_f + assert_raise(TypeError) do + Bug::Integer::MyInteger.new.to_f + end + + begin + Bug::Integer::MyInteger.class_eval do + def to_f + end + end + + assert_nothing_raised do + Bug::Integer::MyInteger.new.to_f + end + ensure + Bug::Integer::MyInteger.class_eval do + remove_method :to_f + end + end + end +end -- cgit v1.2.3