summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSzymon Szukalski <szymon@skas.io>2024-10-25 09:44:09 +1100
committerSzymon Szukalski <szymon@skas.io>2024-10-25 09:44:09 +1100
commitd41d881cf8af8cb8b6cb89b87a351585ee46063c (patch)
tree33587d0ea1d1f48a2ef03c360220acc9cfda3ce4
parentc8b917b1e0f217bf529918d540c49d07a69dba3e (diff)
Move NilPerson to own file
-rw-r--r--lib/nil_person.rb31
-rw-r--r--lib/person.rb32
-rw-r--r--spec/family_spec.rb1
3 files changed, 34 insertions, 30 deletions
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