Class: Hash
- Defined in:
- lib/errgonomic/core_ext/hash.rb,
lib/errgonomic/core_ext/blank.rb
Overview
Two additive lookups; no existing Hash behavior changes. This is as deep as the gem reaches into Hash: the wider Ruby ecosystem leans on Hash semantics too heavily to patch them, so richer behavior lives in Errgonomic::OptionalHash instead.
Instance Method Summary collapse
-
#fetch_option(key) ⇒ Object
Retrieve the value for a key, wrapped in an Option, following key presence as Rust's HashMap#get does: a present key with a nil value is Some(nil); only a missing key is None.
-
#into_optional ⇒ Object
Wrap this hash in an Errgonomic::OptionalHash view.
-
#present? ⇒ Boolean
:nodoc:.
Instance Method Details
#fetch_option(key) ⇒ Object
Retrieve the value for a key, wrapped in an Option, following key presence as Rust's HashMap#get does: a present key with a nil value is Some(nil); only a missing key is None.
20 21 22 23 24 |
# File 'lib/errgonomic/core_ext/hash.rb', line 20 def fetch_option(key) return None() unless key?(key) Some(self[key]) end |
#into_optional ⇒ Object
Wrap this hash in an Errgonomic::OptionalHash view. The wrapper reads and writes this same hash; use its to_h for a detached copy.
33 34 35 |
# File 'lib/errgonomic/core_ext/hash.rb', line 33 def into_optional Errgonomic::OptionalHash.new(self) end |
#present? ⇒ Boolean
:nodoc:
118 119 120 |
# File 'lib/errgonomic/core_ext/blank.rb', line 118 def present? # :nodoc: !empty? end |