summaryrefslogtreecommitdiff
path: root/lib/nil_person.rb
blob: 607ae779a22d6c758005c43fabb9c3dfcaace91f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# 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

  def to_s
    ''
  end
end