Skip to content

Instantly share code, notes, and snippets.

@nickstenning
Created May 25, 2018 11:10
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 nickstenning/f9e7f2972a54f48021def2da89002296 to your computer and use it in GitHub Desktop.
Save nickstenning/f9e7f2972a54f48021def2da89002296 to your computer and use it in GitHub Desktop.
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