Class: Jinx::ValueTransformerHash
- Includes:
- Hashable
- Defined in:
- lib/jinx/helpers/hashable.rb
Overview
The ValueTransformerHash class pipes the value from a base Hashable into a transformer block.
Instance Method Summary collapse
-
#[](key) ⇒ Object
The value at key after this ValueTransformerHash’s transformer block is applied, or nil if this hash does not contain key.
- #each {|key, value| ... } ⇒ Object
-
#initialize(base) {|value| ... } ⇒ ValueTransformerHash
constructor
Creates a ValueTransformerHash on the base hash and value transformer block.
Methods included from Hashable
#==, #assoc_values, #compact, #compose, #copy_recursive, #detect_key, #detect_key_with_value, #diff, #each_key, #each_pair, #each_value, #enum_keys, #enum_keys_with_value, #enum_values, #filter, #filter_on_key, #filter_on_value, #flatten, #has_key?, #has_value?, #inspect, #join, #keys, #pretty_print, #pretty_print_cycle, #qp, #reject_keys, #reject_values, #select_keys, #select_values, #sort, #split, #to_hash, #to_s, #to_set, #transform_key, #transform_value, #union, #values
Methods included from Enumerable
#collection?, #compact, #compact_map, #detect_value, #detect_with_value, #difference, #empty?, #enumerate, #filter, #first, #flatten, #hashify, #intersect, #join, #last, #partial_sort, #partial_sort_by, #pp_s, #pretty_print, #pretty_print_cycle, #qp, #size, #to_compact_hash, #to_compact_hash_with_index, #to_enum, #to_series, #transform, #transitive_closure, #union
Constructor Details
#initialize(base) {|value| ... } ⇒ ValueTransformerHash
Creates a ValueTransformerHash on the base hash and value transformer block.
433 434 435 436 |
# File 'lib/jinx/helpers/hashable.rb', line 433 def initialize(base, &transformer) @base = base @xfm = transformer end |
Instance Method Details
#[](key) ⇒ Object
Returns the value at key after this ValueTransformerHash’s transformer block is applied, or nil if this hash does not contain key.
441 442 443 |
# File 'lib/jinx/helpers/hashable.rb', line 441 def [](key) @xfm.call(@base[key]) if @base.has_key?(key) end |
#each {|key, value| ... } ⇒ Object
448 449 450 |
# File 'lib/jinx/helpers/hashable.rb', line 448 def each @base.each { |k, v| yield(k, @xfm.call(v)) } end |