Class: NullObject

Inherits:
Object
  • Object
show all
Defined in:
lib/maybe_null/null_object.rb

Overview

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(*args, &block) ⇒ NullObject

Returns:



7
8
9
# File 'lib/maybe_null/null_object.rb', line 7

def method_missing(*args, &block)
  self
end

Instance Method Details

#==(other) ⇒ Object



53
54
55
# File 'lib/maybe_null/null_object.rb', line 53

def ==(other)
  other.is_a?(self.class)
end

#blank?Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/maybe_null/null_object.rb', line 19

def blank?
  true
end

#nil?Boolean

Returns:

  • (Boolean)


15
16
17
# File 'lib/maybe_null/null_object.rb', line 15

def nil?
  true
end

#presenceNilClass

Returns:

  • (NilClass)


28
29
30
# File 'lib/maybe_null/null_object.rb', line 28

def presence
  nil
end

#present?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/maybe_null/null_object.rb', line 23

def present?
  false
end

#respond_to?(*args) ⇒ Boolean

Returns:

  • (Boolean)


11
12
13
# File 'lib/maybe_null/null_object.rb', line 11

def respond_to?(*args)
  true
end

#to_aArray

Returns:

  • (Array)


33
# File 'lib/maybe_null/null_object.rb', line 33

def to_a; [] end

#to_booleanBoolean

Returns:

  • (Boolean)


48
# File 'lib/maybe_null/null_object.rb', line 48

def to_boolean; false end

#to_fFloat

Returns:

  • (Float)


39
# File 'lib/maybe_null/null_object.rb', line 39

def to_f; 0.0 end

#to_hashHash

Returns:

  • (Hash)


51
# File 'lib/maybe_null/null_object.rb', line 51

def to_hash; {} end

#to_iInteger

Returns:

  • (Integer)


42
# File 'lib/maybe_null/null_object.rb', line 42

def to_i; 0 end

#to_intInteger

Returns:

  • (Integer)


45
# File 'lib/maybe_null/null_object.rb', line 45

def to_int; 0 end

#to_sString

Returns:

  • (String)


36
# File 'lib/maybe_null/null_object.rb', line 36

def to_s; "" end