LoginSignup
25
25

More than 5 years have passed since last update.

Railsで月毎の配列を簡潔に作る

Last updated at Posted at 2015-08-07

下記のような配列が欲しい。中身はDateクラスで

[2014/8/1, 2014/9/1, 2014/10/1, ...2015/8/1]

同僚に聞いてこんな感じで実装

(Date.new(2014, 8, 1) .. Date.today).select{|date| date.day == 1}

こんな候補もあった

(Date.new(2014, 8, 1) .. Date.today).map(&:beginning_of_month).uniq

もうちょっとスマートに書けないかな。

25
25
9

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