Class: RbLovely::SortedHash
Overview
A SortedHash should not be modified during iteration.
This class is only provided if boost is available on the system when the gem is installed as it is built using the Boost Multi-index Containers Library.
Some methods come from the Enumerable module. If you do not find the method you are looking for in this documentation then please look there.
A SortedHash provides hashed unique keys and ordered non-unique values. Values are sorted using “<=>” and keys are tested for equality using “eql?”.
Class Method Summary collapse
-
.[](*content) ⇒ SortedHash
Factory method for creating sorted hash from array.
Instance Method Summary collapse
-
#[](key) ⇒ Object
Retrieve value associated with the corresponding key or nil if the key doesn’t exist.
-
#[]=(key, value) ⇒ Object
Set the value associated with a key.
-
#clear ⇒ Object
Remove all values from the hash.
-
#delete(key) ⇒ Object
Delete the value associated with a key.
-
#each(&block) ⇒ Object
Calls block once for each key, passing the key-value pair as parameters.
-
#empty? ⇒ Boolean
Return true if the hash is empty.
-
#first ⇒ Object
Retrieve first key-value pair as determined by value sort order or nil if the hash is empty.
-
#first_key ⇒ Object
Retrieve first key as determined by value sort order or nil if the hash is empty.
-
#first_value ⇒ Array
Retrieve first value as determined by value sort order or nil if the hash is empty.
-
#include?(key) ⇒ Boolean
(also: #has_key?, #key?)
Return true if the key is contained in the hash.
-
#initialize(content = [], compare: nil) ⇒ SortedHash
constructor
A new instance of SortedHash.
-
#last ⇒ Array
Retrieve last key-value pair as determined by value sort order or nil if the hash is empty.
-
#last_key ⇒ Object
Retrieve last key as determined by value sort order or nil if the hash is empty.
-
#last_value ⇒ Object
Retrieve last value as determined by value sort order or nil if the hash is empty.
-
#length ⇒ Number
Gets the number of elements in the hash.
-
#pop ⇒ Array
Remove the last key-value pair in the hash and return it or return nil if the hash is empty.
-
#pop_key ⇒ Object
Remove the last key-value pair in the hash and return the key or return nil if the hash is empty.
-
#pop_value ⇒ Object
Remove the last key-value pair in the hash and return it or return nil if the hash is empty.
-
#replace(key, value) ⇒ Object
Set the value associated with a key.
-
#shift ⇒ Array
Remove the first key-value pair in the hash and return it or return nil if the hash is empty.
-
#shift_key ⇒ Object
Remove the first key-value pair in the hash and return the key or return nil if the hash is empty.
-
#shift_value ⇒ Object
Remove the first key-value pair in the hash and return it or return nil if the hash is empty.
Constructor Details
#initialize(content = [], compare: nil) ⇒ SortedHash
Returns a new instance of SortedHash.
181 |
# File 'yard.rb', line 181 def initialize content = [], compare: nil ; end |
Class Method Details
.[](*content) ⇒ SortedHash
Factory method for creating sorted hash from array.
190 |
# File 'yard.rb', line 190 def self.[](*content) ; end |
Instance Method Details
#[](key) ⇒ Object
Retrieve value associated with the corresponding key or nil if the key doesn’t exist.
239 |
# File 'yard.rb', line 239 def [](key) ; end |
#[]=(key, value) ⇒ Object
Set the value associated with a key. If the key already then it and its value are removed.
198 |
# File 'yard.rb', line 198 def []=(key, value) ; end |
#clear ⇒ Object
Remove all values from the hash.
231 |
# File 'yard.rb', line 231 def clear ; end |
#delete(key) ⇒ Object
Delete the value associated with a key.
215 |
# File 'yard.rb', line 215 def delete key ; end |
#each(&block) ⇒ Object
Calls block once for each key, passing the key-value pair as parameters.
223 |
# File 'yard.rb', line 223 def each(&block) ; end |
#empty? ⇒ Boolean
Return true if the hash is empty.
372 |
# File 'yard.rb', line 372 def empty? ; end |
#first ⇒ Object
Retrieve first key-value pair as determined by value sort order or nil if the hash is empty.
252 |
# File 'yard.rb', line 252 def first ; end |
#first_key ⇒ Object
Retrieve first key as determined by value sort order or nil if the hash is empty.
268 |
# File 'yard.rb', line 268 def first_key ; end |
#first_value ⇒ Array
Retrieve first value as determined by value sort order or nil if the hash is empty.
260 |
# File 'yard.rb', line 260 def first_value ; end |
#include?(key) ⇒ Boolean Also known as: has_key?, key?
Return true if the key is contained in the hash.
243 |
# File 'yard.rb', line 243 def include?(key) ; end |
#last ⇒ Array
Retrieve last key-value pair as determined by value sort order or nil if the hash is empty.
276 |
# File 'yard.rb', line 276 def last ; end |
#last_key ⇒ Object
Retrieve last key as determined by value sort order or nil if the hash is empty.
290 |
# File 'yard.rb', line 290 def last_key ; end |
#last_value ⇒ Object
Retrieve last value as determined by value sort order or nil if the hash is empty.
283 |
# File 'yard.rb', line 283 def last_value ; end |
#length ⇒ Number
Gets the number of elements in the hash.
367 |
# File 'yard.rb', line 367 def length ; end |
#pop ⇒ Array
Remove the last key-value pair in the hash and return it or return nil if the hash is empty.
326 |
# File 'yard.rb', line 326 def pop ; end |
#pop_key ⇒ Object
Remove the last key-value pair in the hash and return the key or return nil if the hash is empty.
335 |
# File 'yard.rb', line 335 def pop_key ; end |
#pop_value ⇒ Object
Remove the last key-value pair in the hash and return it or return nil if the hash is empty.
344 |
# File 'yard.rb', line 344 def pop_value ; end |
#replace(key, value) ⇒ Object
Set the value associated with a key. If the key already then it and its value are removed.
206 |
# File 'yard.rb', line 206 def replace(key, value) ; end |
#shift ⇒ Array
Remove the first key-value pair in the hash and return it or return nil if the hash is empty.
299 |
# File 'yard.rb', line 299 def shift ; end |
#shift_key ⇒ Object
Remove the first key-value pair in the hash and return the key or return nil if the hash is empty.
308 |
# File 'yard.rb', line 308 def shift_key ; end |
#shift_value ⇒ Object
Remove the first key-value pair in the hash and return it or return nil if the hash is empty.
317 |
# File 'yard.rb', line 317 def shift_value ; end |