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, #blank?, #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, #present?, #pretty_print, #respond_to_missing?, #some_and, #tap_some, #to_a, #to_json, #to_s, #unwrap!, #unwrap_or, #unwrap_or_else, #xor, #zip, #zip_with

Constructor Details

#initialize(value) ⇒ Some

Returns a new instance of Some.



513
514
515
516
# File 'lib/errgonomic/option.rb', line 513

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.



511
512
513
# File 'lib/errgonomic/option.rb', line 511

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))"


534
535
536
# File 'lib/errgonomic/option.rb', line 534

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

#none?Boolean

Returns:

  • (Boolean)


522
523
524
# File 'lib/errgonomic/option.rb', line 522

def none?
  false
end

#some?Boolean

Returns:

  • (Boolean)


518
519
520
# File 'lib/errgonomic/option.rb', line 518

def some?
  true
end