Last active
November 20, 2019 03:59
-
-
Save higaki/5f8c5a7030d7a013bcd8930005bc147b 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
RUBY_VERSION # => "2.7.0" | |
def foo?(str) | |
case str | |
when "foo" then true | |
else false | |
end | |
# "foo" === str | |
end | |
foo?("foo") # => true | |
foo?("bar") # => false | |
foo?(0) # => false | |
foo?(nil) # => false | |
"foo" === "foo" # => true | |
"foo" === "bar" # => false | |
def string?(x) | |
case x | |
when String then true | |
else false | |
end | |
end | |
string?("foo") # => true | |
string?(1) # => false | |
"foo".is_a? String # => true | |
String === "foo" # => true | |
"foo" === String # => false | |
def enumerable?(x) | |
case x | |
when Enumerable then true | |
else false | |
end | |
end | |
enumerable?("foo") # => false | |
enumerable?(2) # => false | |
enumerable?([2]) # => true | |
enumerable?(2..3) # => true | |
enumerable?({}) # => true | |
enumerable?(nil) # => false |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment