Class: Array
- Defined in:
- lib/errgonomic/core_ext/array.rb,
lib/errgonomic/core_ext/blank.rb
Overview
Two additive lookups; no existing Array behavior changes, for the same reasons given in core_ext/hash.rb.
Instance Method Summary collapse
-
#fetch_option(index) ⇒ Object
Retrieve the element at an integer index, wrapped in an Option, following element presence as Rust's slice get does: an element holding nil is Some(nil); only an out-of-bounds index is None.
-
#into_optional ⇒ Object
Wrap this array in an Errgonomic::OptionalArray view.
-
#present? ⇒ Boolean
:nodoc:.
Instance Method Details
#fetch_option(index) ⇒ Object
Retrieve the element at an integer index, wrapped in an Option, following element presence as Rust's slice get does: an element holding nil is Some(nil); only an out-of-bounds index is None.
18 19 20 21 22 23 24 25 26 |
# File 'lib/errgonomic/core_ext/array.rb', line 18 def fetch_option(index) unless index.is_a?(::Integer) raise Errgonomic::TypeMismatchError, "index must be an Integer, got #{index.class}" end return None() unless (-length...length).cover?(index) Some(self[index]) end |
#into_optional ⇒ Object
Wrap this array in an Errgonomic::OptionalArray view. The wrapper reads and writes this same array; use its to_a for a detached copy.
35 36 37 |
# File 'lib/errgonomic/core_ext/array.rb', line 35 def into_optional Errgonomic::OptionalArray.new(self) end |
#present? ⇒ Boolean
:nodoc:
104 105 106 |
# File 'lib/errgonomic/core_ext/blank.rb', line 104 def present? # :nodoc: !empty? end |