Skip to content

Instantly share code, notes, and snippets.

@enebo
Created September 11, 2020 17:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save enebo/42b4c2b29897ba79aea077606643f9ff to your computer and use it in GitHub Desktop.
Save enebo/42b4c2b29897ba79aea077606643f9ff to your computer and use it in GitHub Desktop.
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