Backport #5876
closedWithin one module, including second module in a class causes errors in class equivalence ('object.class ==' is wrong)
Description
If within one module, another module is included in a class, including a built-in class like Array, the equivalence operators '==' and '!=' for that class produce errors. The general form that produces the error is:
module Module1
class C
include Module2
end
end
c = Module1::C.new
puts (c.class == C ? 'correct' : 'incorrect')
produces 'incorrect'
The output from the attached code illustrates the problem with the built-in class Array:
ruby 1.8.7 (2011-06-30 patchlevel 352) [i386-mingw32]
FIRST: Testing Within a Module: Displays the Problem and the Workaround
= Converting to Strings
Compare the results for Testing Equivalences of
Classes and Classes Converted to String:
Testing Class Equivalence:
The class is an array: Array
But we're in the branch where array class equivalence
tested false, so there's a problem!
WORKAROUND: Testing Equivalence After Converting to Strings:
No Problem
SECOND: Testing Outside a Module: No problem
Class and Class Converted to String:
Testing Class Equivalence
No Problem
Testing Equivalence After Converting to Strings
No Problem
Files
Updated by now (Nikolai Weibull) about 12 years ago
On Tue, Jan 10, 2012 at 21:59, Nick Gunther nlgunther@gmail.com wrote:
module Module1
class C
include Module2
end
end
c = Module1::C.new
puts (c.class == C ? 'correct' : 'incorrect')produces 'incorrect'
c.class == Module1::C ? 'correct' : 'incorrect' # => "correct"
Updated by jeremyevans0 (Jeremy Evans) over 4 years ago
- Tracker changed from Bug to Backport
- Project changed from Ruby 1.8 to Backport187
- Status changed from Open to Rejected
- ruby -v deleted (
ruby 1.8.7 (2011-06-30 patchlevel 352) [i386-mingw32])