Skip to content

Instantly share code, notes, and snippets.

@Y-Fujikawa
Created June 17, 2017 06:56
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 Y-Fujikawa/0aca6c6235c5e173bb57914774b6aec0 to your computer and use it in GitHub Desktop.
Save Y-Fujikawa/0aca6c6235c5e173bb57914774b6aec0 to your computer and use it in GitHub Desktop.
配列の展開のサンプルソース
# 引数を元にメッセージを表示する
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