Project

General

Profile

Actions

Feature #13025

closed

String equality operator does not perform implicit conversion

Added by johncarney (John Carney) over 7 years ago. Updated over 7 years ago.

Status:
Feedback
Assignee:
-
Target version:
-
[ruby-core:78594]

Description

According to the documentation, String#== should perform implicit conversion of non-strings, but this is not happening.

class SomeClass
  def initialize(value)
    @value = value
  end

  def to_str
    @value.to_s
  end
end

"text" == SomeClass.new("text")
# => false (expected true)

Other operators work as expected:

"text" + SomeClass.new("text")
# => "texttext"

"text" <=> SomeClass.new("text")
# => 0

Updated by nobu (Nobuyoshi Nakada) over 7 years ago

  • Tracker changed from Bug to Feature
  • Description updated (diff)
  • Status changed from Open to Feedback

What documentation do you refer?
The document of 2.3 says:

If obj is not an instance of String but responds to to_str, then the
two strings are compared using case equality Object#===.

(the method to be called is wrong, though)

Do you suggest changing the fallback method?

Actions

Also available in: Atom PDF

Like0
Like0