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.



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



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

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



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

def +(other) = other

#as_jsonObject



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

def as_json = nil

#coerce(other) ⇒ Object



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

def coerce(other) = [self, other]

#inspectObject



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

def inspect = to_s

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

Returns:

  • (Boolean)


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

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

#to_sObject



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

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