Project

General

Profile

Actions

Backport #5876

closed

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

Added by nlgunther (Nick Gunther) about 12 years ago. Updated over 4 years ago.

Status:
Rejected
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

Updated by now (Nikolai Weibull) about 12 years ago

On Tue, Jan 10, 2012 at 21:59, Nick Gunther 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"

Actions #2

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])
Actions

Also available in: Atom PDF

Like0
Like0Like0