Project

General

Profile

Backport #5876

Within one module, including second module in a class causes errors in class equivalence ('object.class ==' is wrong)

Added by nlgunther (Nick Gunther) over 7 years ago. Updated 7 days ago.

Status:
Rejected
Priority:
Normal
Assignee:
-
[ruby-core:42045]

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

FilesShowingModuleProblems.zip (872 Bytes) FilesShowingModuleProblems.zip ModuleInClassInModule nlgunther (Nick Gunther), 01/11/2012 05:59 AM
testModule.rb (1.78 KB) testModule.rb nlgunther (Nick Gunther), 01/11/2012 05:59 AM
OtherFileWithModules.rb (24 Bytes) OtherFileWithModules.rb nlgunther (Nick Gunther), 01/11/2012 05:59 AM

History

Updated by now (Nikolai Weibull) over 7 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"

#2

Updated by jeremyevans0 (Jeremy Evans) 7 days ago

  • ruby -v deleted (ruby 1.8.7 (2011-06-30 patchlevel 352) [i386-mingw32])
  • Status changed from Open to Rejected
  • Project changed from Ruby 1.8 to Backport187
  • Tracker changed from Bug to Backport

Also available in: Atom PDF