LoginSignup
1
1

More than 1 year has passed since last update.

ブロック引数で渡ってきたhashを、キーを変数名にしてローカル変数に展開する

Posted at

あんま見ない書き方だったのでメモがてら残しておく

list = [{a: 1, b: 2}]

list.each do |args|
  args => {a:, b:}

  p a
  p b
end

# 実行結果
1
2                                                     
1
1
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1