Class: LazyGraph::MissingValue

Inherits:
Object
  • Object
show all
Defined in:
lib/lazy_graph/missing_value.rb

Overview

Represents a value that is missing or undefined, allowing for graceful handling of method calls and JSON serialization even when the value is not present.

Constant Summary collapse

BLANK =
new('')

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(details) ⇒ MissingValue

Returns a new instance of MissingValue.

[View source]

9
# File 'lib/lazy_graph/missing_value.rb', line 9

def initialize(details) = @details = details

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object

[View source]

26
27
28
29
30
31
# File 'lib/lazy_graph/missing_value.rb', line 26

def method_missing(method, *args, &block)
  return super if method == :to_ary
  return self if self == BLANK

  MissingValue.new(:"#{details}##{method}#{args.any? ? :"(#{args.inspect[1...-1]})" : :''}")
end

Instance Attribute Details

#detailsObject (readonly)

Returns the value of attribute details.


7
8
9
# File 'lib/lazy_graph/missing_value.rb', line 7

def details
  @details
end

Instance Method Details

#+(other) ⇒ Object

[View source]

15
# File 'lib/lazy_graph/missing_value.rb', line 15

def +(other) = other

#==(other) ⇒ Object

[View source]

20
21
22
23
24
# File 'lib/lazy_graph/missing_value.rb', line 20

def ==(other)
  return true if other.nil?

  super
end

#as_jsonObject

[View source]

13
# File 'lib/lazy_graph/missing_value.rb', line 13

def as_json = nil

#coerce(other) ⇒ Object

[View source]

12
# File 'lib/lazy_graph/missing_value.rb', line 12

def coerce(other) = [self, other]

#inspectObject

[View source]

11
# File 'lib/lazy_graph/missing_value.rb', line 11

def inspect = to_s

#respond_to_missing?(_method_name, _include_private = false) ⇒ Boolean

Returns:

  • (Boolean)
[View source]

16
# File 'lib/lazy_graph/missing_value.rb', line 16

def respond_to_missing?(_method_name, _include_private = false) = true

#to_fObject

[View source]

18
# File 'lib/lazy_graph/missing_value.rb', line 18

def to_f = 0.0

#to_hObject

[View source]

14
# File 'lib/lazy_graph/missing_value.rb', line 14

def to_h = nil

#to_iObject

[View source]

17
# File 'lib/lazy_graph/missing_value.rb', line 17

def to_i = 0

#to_sObject

[View source]

10
# File 'lib/lazy_graph/missing_value.rb', line 10

def to_s = "MISSING[#{@details}]"