Skip to content

Instantly share code, notes, and snippets.

@boc-tothefuture
Created November 30, 2020 20:43
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 boc-tothefuture/48d87ada10e0bb8efa144df9693089d6 to your computer and use it in GitHub Desktop.
Save boc-tothefuture/48d87ada10e0bb8efa144df9693089d6 to your computer and use it in GitHub Desktop.
class Foo
def initialize()
@num=5
end
def coerce(other)
puts "Coerce called with #{other.inspect} and class #{other.class}"
[other, @num]
end
def to_int
puts "Called to_int"
@num
end
def to_i
puts "Called to_i"
@num
end
end
puts 5 === Foo.new
puts (1..10) === Foo.new
#####
# Output
# false
# Coerce called with 1 and class Integer
# false
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment