summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorSzymon Szukalski <szymon@skas.io>2024-10-25 11:34:27 +1100
committerSzymon Szukalski <szymon@skas.io>2024-10-25 11:34:27 +1100
commit29fe91901a188af552a0bbaeb59eaf056fbe385d (patch)
tree533a1e47bd5b9bdeb83e4ea70417b214bff26f9d /lib
parent524064f6313bb62c54d51d4ca37825a878dbf1b6 (diff)
Remove equality checks due to infinite loop
Diffstat (limited to 'lib')
-rw-r--r--lib/family_tree.rb5
-rw-r--r--lib/person.rb23
2 files changed, 4 insertions, 24 deletions
diff --git a/lib/family_tree.rb b/lib/family_tree.rb
index 908cb65..5ba8c72 100644
--- a/lib/family_tree.rb
+++ b/lib/family_tree.rb
@@ -35,9 +35,12 @@ class FamilyTree
# @return [String] 'CHILD_ADDED' if the child is added successfully, 'CHILD_ADDITION_FAILED' otherwise.
def add_child(mothers_name, name, gender)
result = find_person_in_families(mothers_name)
+ parent = result[:person]
parent_of_family = result[:parent_of_family]
- return 'CHILD_ADDITION_FAILED' if parent_of_family.nil? || parent_of_family.mother.is_a?(NilPerson)
+ if parent_of_family.nil? || parent_of_family.mother.is_a?(NilPerson) || parent_of_family.father.eql?(parent)
+ return 'CHILD_ADDITION_FAILED'
+ end
return 'CHILD_ADDITION_FAILED' if parent_of_family.children.any? { |child| child.name.casecmp(name).zero? }
diff --git a/lib/person.rb b/lib/person.rb
index 9a3dcb6..0b8c634 100644
--- a/lib/person.rb
+++ b/lib/person.rb
@@ -17,29 +17,6 @@ class Person
@spouse = spouse
end
- # Checks equality with another object.
- #
- # @param other [Object] The object to compare with.
- # @return [Boolean] True if the other object is a Person with the same name, gender, and spouse, false otherwise.
- def ==(other)
- other.is_a?(Person) && name == other.name && gender == other.gender && spouse == other.spouse
- end
-
- # Checks equality with another object (alias for ==).
- #
- # @param other [Object] The object to compare with.
- # @return [Boolean] True if the other object is a Person with the same name, gender, and spouse, false otherwise.
- def eql?(other)
- self == other
- end
-
- # Computes the hash code for the Person object.
- #
- # @return [Integer] The hash code based on the name, gender, and spouse.
- def hash
- [name, gender, spouse].hash
- end
-
# Returns a string representation of the Person.
#
# @return [String] The string representation in the format "name (gender)".