Class: Calrom::Month
- Defined in:
- lib/calrom/date_range.rb
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #each_month {|_self| ... } ⇒ Object
-
#initialize(year, month) ⇒ Month
constructor
A new instance of Month.
- #succ ⇒ Object
- #to_s ⇒ Object
Methods inherited from DateRange
Constructor Details
#initialize(year, month) ⇒ Month
Returns a new instance of Month.
67 68 69 70 71 72 |
# File 'lib/calrom/date_range.rb', line 67 def initialize(year, month) @year = year @month = month super Date.new(year, month, 1), Date.new(year, month, -1) end |
Instance Method Details
#<=>(other) ⇒ Object
89 90 91 92 93 94 95 96 97 |
# File 'lib/calrom/date_range.rb', line 89 def <=>(other) years_cmp = year <=> other.year if years_cmp != 0 years_cmp else month <=> other.month end end |
#each_month {|_self| ... } ⇒ Object
78 79 80 81 82 |
# File 'lib/calrom/date_range.rb', line 78 def each_month return to_enum(:each_month) unless block_given? yield self end |
#succ ⇒ Object
84 85 86 87 |
# File 'lib/calrom/date_range.rb', line 84 def succ n = Date.new(@year, @month, 1).next_month self.class.new(n.year, n.month) end |
#to_s ⇒ Object
74 75 76 |
# File 'lib/calrom/date_range.rb', line 74 def to_s first.strftime '%B %Y' end |