instance method String#==

self == other -> bool[permalink][rdoc][edit]
self === other -> bool

other が文字列の場合、String#eql? と同様に文字列の内容を比較します。

other が文字列でない場合、 other.to_str が定義されていれば other == self の結果を返します。(ただし、 other.to_str は実行されません。) そうでなければ false を返します。

[PARAM] other:
任意のオブジェクト
[RETURN]
true か false


stringlike = Object.new

def stringlike.==(other)
  "string" == other
end

p "string".eql?(stringlike) #=> false
p "string" == stringlike    #=> false

def stringlike.to_str
  raise
end

p "string".eql?(stringlike) #=> false
p "string" == stringlike    #=> true

[SEE_ALSO] String#eql?