Created
May 25, 2018 11:10
-
-
Save nickstenning/f9e7f2972a54f48021def2da89002296 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
def responds_to?(method_name) | |
->(obj) { obj.respond_to?(method_name) } | |
end | |
[ | |
1, | |
"string", | |
%w{an array}, | |
{a: 'hash'} | |
].each do |object| | |
case object | |
when String, Integer | |
puts object | |
when responds_to?(:join) | |
puts object.join(' ') | |
else | |
puts object.inspect | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment