Skip to content

Instantly share code, notes, and snippets.

@seak0503
Created April 28, 2016 05:47
Show Gist options
  • Save seak0503/bf619a48f313225e91b781c8f9716f8f to your computer and use it in GitHub Desktop.
Save seak0503/bf619a48f313225e91b781c8f9716f8f to your computer and use it in GitHub Desktop.
Ruby 配列を別の配列の中で展開する

irb(main):011:0> test = [ "test1", "test2", "test3", "test4"] => ["test1", "test2", "test3", "test4"]

作成した配列testの先頭にアスタリスク(*)をつけて、別の配列内(opts)に おくと、opts配列の中でtest配列が展開される

irb(main):016:0* opts = ["a", *test, "b"] => ["a", "test1", "test2", "test3", "test4", "b"]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment