Created
June 17, 2017 06:56
-
-
Save Y-Fujikawa/0aca6c6235c5e173bb57914774b6aec0 to your computer and use it in GitHub Desktop.
配列の展開のサンプルソース
This file contains 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 display_messages(name, message_first, message_second) | |
p "#{name} : #{message_first}" | |
p "#{name} : #{message_second}" | |
end | |
# 実行(正常動作) | |
messages = %w(Hello Goodbye) | |
display_messages 'John', *messages | |
# 実行(例外発生) | |
# 受取先のメソッドに対して、引数以上の要素を渡した場合、エラーとなる | |
messages.push 'Thank you' | |
display_messages 'John', *messages |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment