summaryrefslogtreecommitdiff
path: root/lib/person.rb
diff options
context:
space:
mode:
authorSzymon Szukalski <szymon@skas.io>2024-10-25 10:00:36 +1100
committerSzymon Szukalski <szymon@skas.io>2024-10-25 10:00:36 +1100
commit05fda6c29f0fe4742b7ea6b237ea98f737b68b8b (patch)
tree3fca7845fc80f0d93370d2bdadb647f3f9c65d25 /lib/person.rb
parentd41d881cf8af8cb8b6cb89b87a351585ee46063c (diff)
Document code with YARD
Diffstat (limited to 'lib/person.rb')
-rw-r--r--lib/person.rb20
1 files changed, 20 insertions, 0 deletions
diff --git a/lib/person.rb b/lib/person.rb
index 8571754..9a3dcb6 100644
--- a/lib/person.rb
+++ b/lib/person.rb
@@ -2,27 +2,47 @@
require_relative 'nil_person'
+# Person class representing an individual with a name, gender, and spouse.
class Person
attr_accessor :name, :gender, :spouse
+ # Initializes a new Person object.
+ #
+ # @param name [String] The name of the person.
+ # @param gender [String] The gender of the person.
+ # @param spouse [Person, NilPerson] The spouse of the person, defaults to NilPerson.
def initialize(name, gender, spouse = NilPerson.new)
@name = name
@gender = gender
@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)".
def to_s
"#{name} (#{gender})"
end