Skip to content

Instantly share code, notes, and snippets.

@kyuden
Last active December 26, 2015 00:38
Show Gist options
  • Save kyuden/7065388 to your computer and use it in GitHub Desktop.
Save kyuden/7065388 to your computer and use it in GitHub Desktop.
可変長引数、配列展開
class MyClass
#可変長引数(複数の引数を配列として受け取る)
def greet( *names, message )
names.each do |name|
puts "#{name}、#{message}"
end
end
end
name_list = %w(tom akira joy!)
my_class = MyClass.new
my_class.greet("tom", "akira", "joy", "hello")
my_class.greet(name_list, "hello")
#配列展開
my_class.greet(*name_list, "hello")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment