Skip to content

Instantly share code, notes, and snippets.

@elikem
Last active August 29, 2015 13:57
Show Gist options
  • Select an option

  • Save elikem/9443798 to your computer and use it in GitHub Desktop.

Select an option

Save elikem/9443798 to your computer and use it in GitHub Desktop.
object.respond_to?("each")
# Say hi to everybody
def say_hi
if @names.nil?
puts "..."
elsif @names.respond_to?("each")
# @names is a list of some kind, iterate!
@names.each do |name|
puts "Hello #{name}!"
end
else
puts "Hello #{@names}!"
end
end
%w(1,2,3,4,5).respond_to?('each')
#=> true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment