Class: Code::Object::Nothing

Inherits:
Object
  • 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

Class Method Summary collapse

Instance Method Summary collapse

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