Skip to content

Commit

Permalink
Add Month#inspect method
Browse files Browse the repository at this point in the history
  • Loading branch information
timcraft committed Jan 2, 2025
1 parent 0d919f8 commit 9b6510c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
4 changes: 4 additions & 0 deletions lib/month.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ def to_s

alias_method :iso8601, :to_s

def inspect
"<Month: #{to_s}>"
end

def name
NAMES.fetch(@number)
end
Expand Down
10 changes: 8 additions & 2 deletions spec/month_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,23 @@
end

describe '#to_s' do
it 'returns a string containing the year and zero padded number of the month' do
it 'returns a string containing the year and number' do
expect(Month.new(2014, 1).to_s).to eq('2014-01')
end
end

describe '#iso8601' do
it 'returns a string containing the year and zero padded number of the month' do
it 'returns a string containing the year and number' do
expect(Month.new(2014, 1).iso8601).to eq('2014-01')
end
end

describe '#inspect' do
it 'returns a string containing the year and number' do
expect(Month.new(2014, 1).inspect).to eq('<Month: 2014-01>')
end
end

describe '#name' do
it 'returns the name of the month' do
expect(Month.new(2014, 1).name).to eq(:January)
Expand Down

0 comments on commit 9b6510c

Please sign in to comment.