Class: MyBirthday
- Inherits:
-
Object
- Object
- MyBirthday
- Includes:
- Contracts::Core, Contracts::Invariants
- Defined in:
- lib/contracts-ruby2/spec/fixtures/fixtures.rb,
lib/contracts-ruby3/spec/fixtures/fixtures.rb
Overview
invariant example (silliest implementation ever)
Instance Attribute Summary collapse
-
#day ⇒ Object
Returns the value of attribute day.
-
#month ⇒ Object
Returns the value of attribute month.
Instance Method Summary collapse
- #clever_next_day! ⇒ Object
- #clever_next_month! ⇒ Object
-
#initialize(day, month) ⇒ MyBirthday
constructor
A new instance of MyBirthday.
- #next_year! ⇒ Object
- #silly_next_day! ⇒ Object
- #silly_next_month! ⇒ Object
Methods included from Contracts::Invariants
common, extended, included, #verify_invariants!
Methods included from Contracts::Core
Constructor Details
#initialize(day, month) ⇒ MyBirthday
Returns a new instance of MyBirthday.
532 533 534 535 |
# File 'lib/contracts-ruby2/spec/fixtures/fixtures.rb', line 532 def initialize(day, month) @day = day @month = month end |
Instance Attribute Details
#day ⇒ Object
Returns the value of attribute day.
531 532 533 |
# File 'lib/contracts-ruby2/spec/fixtures/fixtures.rb', line 531 def day @day end |
#month ⇒ Object
Returns the value of attribute month.
531 532 533 |
# File 'lib/contracts-ruby2/spec/fixtures/fixtures.rb', line 531 def month @month end |
Instance Method Details
#clever_next_day! ⇒ Object
548 549 550 551 |
# File 'lib/contracts-ruby2/spec/fixtures/fixtures.rb', line 548 def clever_next_day! return clever_next_month! if day == 31 self.day += 1 end |
#clever_next_month! ⇒ Object
554 555 556 557 558 |
# File 'lib/contracts-ruby2/spec/fixtures/fixtures.rb', line 554 def clever_next_month! return next_year! if month == 12 self.month += 1 self.day = 1 end |
#next_year! ⇒ Object
561 562 563 564 |
# File 'lib/contracts-ruby2/spec/fixtures/fixtures.rb', line 561 def next_year! self.month = 1 self.day = 1 end |
#silly_next_day! ⇒ Object
538 539 540 |
# File 'lib/contracts-ruby2/spec/fixtures/fixtures.rb', line 538 def silly_next_day! self.day += 1 end |
#silly_next_month! ⇒ Object
543 544 545 |
# File 'lib/contracts-ruby2/spec/fixtures/fixtures.rb', line 543 def silly_next_month! self.month += 1 end |