Class: Jinx::Hasher::SortedHash
- Includes:
- Jinx::Hasher
- Defined in:
- lib/jinx/helpers/hasher.rb
Overview
Instance Method Summary collapse
- #each ⇒ Object
-
#initialize(base, &comparator) ⇒ SortedHash
constructor
A new instance of SortedHash.
Methods included from Jinx::Hasher
#==, #[], #assoc_values, #compact, #compose, #copy_recursive, #detect_hash_value, #detect_key, #detect_key_with_value, #detect_value, #difference, #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
#enumerate, #pp_s, #pretty_print, #pretty_print_cycle, #qp, #to_enum, #transitive_closure
Methods included from Collection
#compact, #compact_map, #detect_value, #detect_with_value, #difference, #empty?, #filter, #first, #flatten, #hashify, #intersect, #join, #last, #partial_sort, #partial_sort!, #partial_sort_by, #size, #to_compact_hash, #to_compact_hash_with_index, #to_series, #transform, #union
Constructor Details
#initialize(base, &comparator) ⇒ SortedHash
Returns a new instance of SortedHash.
420 421 422 423 |
# File 'lib/jinx/helpers/hasher.rb', line 420 def initialize(base, &comparator) @base = base @comparator = comparator end |
Instance Method Details
#each ⇒ Object
425 426 427 |
# File 'lib/jinx/helpers/hasher.rb', line 425 def each @base.keys.sort { |k1, k2| @comparator ? @comparator.call(k1, k2) : k1 <=> k2 }.each { |k| yield(k, @base[k]) } end |