From d41d881cf8af8cb8b6cb89b87a351585ee46063c Mon Sep 17 00:00:00 2001 From: Szymon Szukalski Date: Fri, 25 Oct 2024 09:44:09 +1100 Subject: Move NilPerson to own file --- lib/nil_person.rb | 31 +++++++++++++++++++++++++++++++ lib/person.rb | 32 ++------------------------------ spec/family_spec.rb | 1 + 3 files changed, 34 insertions(+), 30 deletions(-) create mode 100644 lib/nil_person.rb diff --git a/lib/nil_person.rb b/lib/nil_person.rb new file mode 100644 index 0000000..30a175f --- /dev/null +++ b/lib/nil_person.rb @@ -0,0 +1,31 @@ +# frozen_string_literal: true + +class NilPerson + def name + nil + end + + def father + self + end + + def mother + self + end + + def gender + nil + end + + def ==(other) + other.is_a?(NilPerson) + end + + def eql?(other) + self == other + end + + def to_s + '' + end +end diff --git a/lib/person.rb b/lib/person.rb index a40efbe..8571754 100644 --- a/lib/person.rb +++ b/lib/person.rb @@ -1,5 +1,7 @@ # frozen_string_literal: true +require_relative 'nil_person' + class Person attr_accessor :name, :gender, :spouse @@ -25,33 +27,3 @@ class Person "#{name} (#{gender})" end end - -class NilPerson - def name - nil - end - - def father - self - end - - def mother - self - end - - def gender - nil - end - - def ==(other) - other.is_a?(NilPerson) - end - - def eql?(other) - self == other - end - - def to_s - '' - end -end diff --git a/spec/family_spec.rb b/spec/family_spec.rb index 7247648..615bbc6 100644 --- a/spec/family_spec.rb +++ b/spec/family_spec.rb @@ -2,6 +2,7 @@ require_relative '../lib/family' require_relative '../lib/person' +require_relative '../lib/nil_person' require_relative '../lib/gender' RSpec.describe Family do -- cgit v1.2.3