Class: Errgonomic::Option::None

Inherits:
Any show all
Defined in:
lib/errgonomic/option.rb,
lib/errgonomic/rails/active_record_optional.rb

Overview

A None answers nil? like nil itself, so ActiveRecord internals that check for nil treat an absent value as absent.

Constant Summary

Constants inherited from Any

Any::NUDGED, Any::RUST_SPELLINGS

Instance Method Summary collapse

Methods inherited from Any

#!=, #<=>, #==, #===, #and, #and_then, #as_json, #blank?, #blank_or, #blank_or_else, #blank_or_raise!, #deconstruct, #each, #eql?, #expect!, #filter, #flatten, #hash, #map, #map_or, #map_or_else, #method_missing, #none_or, #ok_or, #ok_or_else, #or, #or_else, #presence, #present?, #present_or, #present_or_else, #present_or_raise!, #pretty_print, #respond_to_missing?, #some_and, #tap_some, #to_a, #to_json, #to_option, #to_s, #try, #try!, #unwrap!, #unwrap_or, #unwrap_or_else, #xor, #zip, #zip_with

Constructor Details

#initializeNone

Returns a new instance of None.

Examples:

a None has no value to read, and says so the same way a Some does

begin
  None().value
rescue NoMethodError => e
  e.class
end # => Errgonomic::UnwrappedAccessError
None().frozen? # => true


1005
1006
1007
1008
# File 'lib/errgonomic/option.rb', line 1005

def initialize
  super
  freeze
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Errgonomic::Option::Any

Instance Method Details

#inspectObject

Examples:

None().inspect # => "None"


1020
1021
1022
# File 'lib/errgonomic/option.rb', line 1020

def inspect
  'None'
end

#nil?Boolean

Returns:

  • (Boolean)


433
434
435
# File 'lib/errgonomic/rails/active_record_optional.rb', line 433

def nil?
  true
end

#none?Boolean

Returns:

  • (Boolean)


1014
1015
1016
# File 'lib/errgonomic/option.rb', line 1014

def none?
  true
end

#some?Boolean

Returns:

  • (Boolean)


1010
1011
1012
# File 'lib/errgonomic/option.rb', line 1010

def some?
  false
end