Skip to content

Instantly share code, notes, and snippets.

@higaki
Last active November 20, 2019 03:59
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 higaki/5f8c5a7030d7a013bcd8930005bc147b to your computer and use it in GitHub Desktop.
Save higaki/5f8c5a7030d7a013bcd8930005bc147b to your computer and use it in GitHub Desktop.
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