From 05fda6c29f0fe4742b7ea6b237ea98f737b68b8b Mon Sep 17 00:00:00 2001 From: Szymon Szukalski Date: Fri, 25 Oct 2024 10:00:36 +1100 Subject: Document code with YARD --- lib/nil_person.rb | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'lib/nil_person.rb') 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 -- cgit v1.2.3