Class: MyBirthday

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Methods included from Contracts::Invariants

common, extended, included, #verify_invariants!

Methods included from Contracts::Core

common, extended, included

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

#dayObject

Returns the value of attribute day.



531
532
533
# File 'lib/contracts-ruby2/spec/fixtures/fixtures.rb', line 531

def day
  @day
end

#monthObject

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