Created
November 30, 2020 20:43
-
-
Save boc-tothefuture/48d87ada10e0bb8efa144df9693089d6 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 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