diff options
Diffstat (limited to 'lib/nil_person.rb')
| -rw-r--r-- | lib/nil_person.rb | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/lib/nil_person.rb b/lib/nil_person.rb index 30a175f..607ae77 100644 --- a/lib/nil_person.rb +++ b/lib/nil_person.rb @@ -1,26 +1,49 @@ # frozen_string_literal: true +# NilPerson class following the NullObject pattern. +# This class represents a null object for a person, providing default +# implementations that return nil or self as appropriate. class NilPerson + # Returns the name of the NilPerson. + # + # @return [nil] Always returns nil. def name nil end + # Returns the father of the NilPerson. + # + # @return [NilPerson] Always returns self. def father self end + # Returns the mother of the NilPerson. + # + # @return [NilPerson] Always returns self. def mother self end + # Returns the gender of the NilPerson. + # + # @return [nil] Always returns nil. def gender nil end + # Checks equality with another object. + # + # @param other [Object] The object to compare with. + # @return [Boolean] True if the other object is a NilPerson, false otherwise. def ==(other) other.is_a?(NilPerson) 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 NilPerson, false otherwise. def eql?(other) self == other end |
