Last active
December 26, 2015 00:38
-
-
Save kyuden/7065388 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
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