Created
September 11, 2020 17:34
-
-
Save enebo/42b4c2b29897ba79aea077606643f9ff to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Foo | |
def to_str | |
puts "Foo#to_str" | |
"to_str" | |
end | |
def ==(other) | |
puts "Foo#== #{other}" | |
other == to_str | |
end | |
end | |
# If other is not a String then String#== will examine whether other | |
# responds to 'to_str' it will call '==' on that method. | |
p "to_str" == Foo.new | |
# run: | |
# Foo#== to_str | |
# Foo#to_str | |
# true | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment