Class: Errgonomic::Option::Some

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

Overview

Delegate ActiveRecord lifecycle checks to the wrapped record, so a Some can stand in for its record during persistence.

Constant Summary

Constants inherited from Any

Any::RUST_SPELLINGS

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Any

#<=>, #==, #and, #and_then, #as_json, #blank?, #blank_or, #blank_or_else, #blank_or_raise!, #deconstruct, #eql?, #expect!, #filter, #flatten, #hash, #map, #map_or, #map_or_else, #method_missing, #none_or, #ok, #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, #unwrap!, #unwrap_or, #unwrap_or_else, #xor, #zip, #zip_with

Constructor Details

#initialize(value) ⇒ Some

Returns a new instance of Some.



645
646
647
648
# File 'lib/errgonomic/option.rb', line 645

def initialize(value)
  super()
  @value = value
end

Dynamic Method Handling

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

Instance Attribute Details

#valueObject

Returns the value of attribute value.



643
644
645
# File 'lib/errgonomic/option.rb', line 643

def value
  @value
end

Instance Method Details

#inspectObject

Render like Rust's Debug, delegating to the inner value's inspect so nesting stays unambiguous.

Examples:

Some(5).inspect # => "Some(5)"
Some("x").inspect # => "Some(\"x\")"
Some(nil).inspect # => "Some(nil)"
Some(Some(1)).inspect # => "Some(Some(1))"


666
667
668
# File 'lib/errgonomic/option.rb', line 666

def inspect
  "Some(#{value.inspect})"
end

#none?Boolean

Returns:

  • (Boolean)


654
655
656
# File 'lib/errgonomic/option.rb', line 654

def none?
  false
end

#some?Boolean

Returns:

  • (Boolean)


650
651
652
# File 'lib/errgonomic/option.rb', line 650

def some?
  true
end