LoginSignup
0
0

More than 1 year has passed since last update.

【RSpec】変数名を付けながら大量のデータ作成したとき

Posted at

instance_variable_set

テストで変数名を付けながら大量のデータを作成したいときに便利。

(Date.new(2022, 1, 1)..Date.new(2022, 1, 31)).each_with_index do |date, i|
  instance_variable_set("@date#{i+1}", date)
end

@date1 #=> Sat, 01 Jan 2022
@date2 #=> Sun, 02 Jan 2022
@date3 #=> Mon, 03 Jan 2022
...

参考

0
0
0

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
0
0