Make subclasses to define methods

This commit is contained in:
Nobuyoshi Nakada 2024-06-07 00:50:30 +09:00
parent ec7babd12d
commit e323dbb1bd
No known key found for this signature in database
GPG key ID: 3582D74E1FEE4465

View file

@ -8,19 +8,13 @@ class Test_MyInteger < Test::Unit::TestCase
Bug::Integer::MyInteger.new.to_f Bug::Integer::MyInteger.new.to_f
end end
begin int = Class.new(Bug::Integer::MyInteger) do
Bug::Integer::MyInteger.class_eval do
def to_f def to_f
end end
end end
assert_nothing_raised do assert_nothing_raised do
Bug::Integer::MyInteger.new.to_f int.new.to_f
end
ensure
Bug::Integer::MyInteger.class_eval do
remove_method :to_f
end
end end
end end
@ -29,20 +23,14 @@ class Test_MyInteger < Test::Unit::TestCase
Bug::Integer::MyInteger.new <=> 0 Bug::Integer::MyInteger.new <=> 0
end end
begin int = Class.new(Bug::Integer::MyInteger) do
Bug::Integer::MyInteger.class_eval do
def <=>(other) def <=>(other)
0 0
end end
end end
assert_nothing_raised do assert_nothing_raised do
Bug::Integer::MyInteger.new <=> 0 int.new <=> 0
end
ensure
Bug::Integer::MyInteger.class_eval do
remove_method :<=>
end
end end
end end
end end