Class: Code::Object::Nothing

Inherits:
Code::Object show all
Defined in:
lib/code/object/nothing.rb

Constant Summary collapse

CLASS_DOCUMENTATION =
{
  name: "Nothing",
  description: "represents no value.",
  examples: %w[nothing Nothing.new Nothing.new(1)]
}.freeze
INSTANCE_FUNCTIONS =
{
  "empty?" => {
    name: "empty?",
    description: "returns true because nothing has no contents.",
    examples: %w[nothing.empty? Nothing.new.empty? Nothing.new(1).empty?]
  },
  "to_string" => {
    name: "to_string",
    description: "returns an empty string for nothing.",
    examples: %w[
      nothing.to_string
      Nothing.new.to_string
      Nothing.new(1).to_string
    ]
  },
  "inspect" => {
    name: "inspect",
    description: "returns the source string for nothing.",
    examples: %w[
      nothing.inspect
      Nothing.new.inspect
      Nothing.new(1).inspect
    ]
  }
}.freeze

Constants inherited from Code::Object

CLASS_FUNCTIONS, NUMBER_CLASSES

Constants included from Concerns::Shared

Concerns::Shared::COMPOUND_ASSIGNMENT_OPERATORS, Concerns::Shared::OPERATOR_METHOD_ALIASES, Concerns::Shared::SHARED_OPERATORS

Instance Attribute Summary

Attributes included from Concerns::Shared

#functions, #raw

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Code::Object

class_documentation, class_functions, code_new, #code_new, documentation, documentation_for, documented_functions_for, function_documentation_for, function_documentation_registry_for, functions, inherited_function_documentation_for, instance_functions, maybe, #name, repeat, sorted_dictionary, |

Methods included from Concerns::Shared

#<=>, #==, #as_json, #blank?, #code_and, #code_as_json, #code_blank?, #code_class_functions, #code_compare, #code_deep_duplicate, #code_different, #code_documentable_functions, #code_documentation, #code_duplicate, #code_dynamic_call, #code_equal, #code_exclamation_mark, #code_exclusive_range, #code_false?, #code_falsy?, code_fetch, #code_fetch, #code_functions, code_get, #code_get, #code_greater, #code_greater_or_equal, #code_has_key?, #code_inclusive_range, #code_instance_functions, #code_instance_of?, #code_is_a?, #code_itself, #code_less, #code_less_or_equal, #code_name, #code_nothing?, #code_or, #code_presence, #code_presence_in, #code_present?, #code_respond_to?, #code_same_object?, #code_self, #code_send, code_set, #code_set, #code_something?, #code_strict_different, #code_strict_equal, #code_tap, #code_then, #code_to_boolean, #code_to_class, #code_to_date, #code_to_decimal, #code_to_dictionary, #code_to_duration, #code_to_integer, #code_to_json, #code_to_list, #code_to_nothing, #code_to_parameter, #code_to_range, #code_to_time, #code_true?, #code_truthy?, #eql?, #falsy?, #hash, #inspect, #multi_fetch, #sig, #something?, #succ, #to_code, #to_i, #to_json, #to_s

Constructor Details

#initialize(*_args, **_kargs, &_block) ⇒ Nothing

Returns a new instance of Nothing.



43
44
45
# File 'lib/code/object/nothing.rb', line 43

def initialize(*_args, **_kargs, &_block)
  self.raw = nil
end

Class Method Details

.function_documentation(scope) ⇒ Object



37
38
39
40
41
# File 'lib/code/object/nothing.rb', line 37

def self.function_documentation(scope)
  return INSTANCE_FUNCTIONS if scope == :instance

  {}
end

Instance Method Details

#call(**args) ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
# File 'lib/code/object/nothing.rb', line 47

def call(**args)
  code_operator = args.fetch(:operator, nil).to_code

  case code_operator.to_s
  when "empty?"
    sig(args)
    code_empty?
  else
    super
  end
end

#code_empty?Boolean

Returns:



71
72
73
# File 'lib/code/object/nothing.rb', line 71

def code_empty?
  Boolean.new(true)
end

#code_inspectObject



79
80
81
# File 'lib/code/object/nothing.rb', line 79

def code_inspect
  String.new("nothing")
end

#code_to_stringObject



75
76
77
# File 'lib/code/object/nothing.rb', line 75

def code_to_string
  String.new
end

#nothing?Boolean

Returns:



67
68
69
# File 'lib/code/object/nothing.rb', line 67

def nothing?
  true
end

#present?Boolean

Returns:



63
64
65
# File 'lib/code/object/nothing.rb', line 63

def present?
  false
end

#truthy?Boolean

Returns:



59
60
61
# File 'lib/code/object/nothing.rb', line 59

def truthy?
  false
end