Skip to content

Commit

Permalink
Rank, AbstractDate: fix exception on comparison
Browse files Browse the repository at this point in the history
with instance of a different class
  • Loading branch information
igneus committed Apr 2, 2023
1 parent 34f3665 commit 6c298ac
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/calendarium-romanum/abstract_date.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ def self.from_date(date)
attr_reader :month, :day

def <=>(other)
return nil unless other.class == self.class

if month != other.month
month <=> other.month
else
Expand Down
2 changes: 2 additions & 0 deletions lib/calendarium-romanum/rank.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ def short_desc
end

def <=>(other)
return nil unless other.class == self.class

other.priority <=> priority
end

Expand Down
1 change: 1 addition & 0 deletions spec/abstract_date_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
describe '#==' do
it { expect(AD.new(1, 1)).to be == AD.new(1, 1) }
it { expect(AD.new(1, 1)).not_to be == AD.new(1, 2) }
it { expect(AD.new(1, 1) == 'instance of another class').to be false }
end

describe 'as a Hash key' do
Expand Down
1 change: 1 addition & 0 deletions spec/rank_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
describe '#==' do
it { expect(CR::Ranks[1.2]).to be == CR::Ranks[1.2] }
it { expect(CR::Ranks[1.2]).not_to be == CR::Ranks[1.1] }
it { expect(CR::Ranks::FERIAL == 'instance of another class').to be false }
end

describe 'descriptions' do
Expand Down

0 comments on commit 6c298ac

Please sign in to comment.