Skip to content

Commit

Permalink
update SortedHash docs
Browse files Browse the repository at this point in the history
  • Loading branch information
GarrisonJ committed May 29, 2024
1 parent ddc3ee7 commit af4e8f3
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions lib/sorted_containers/sorted_hash.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,30 @@ module SortedContainers
# - #index
# - #last
# - #pop
#
# Addtionally, there are methods that work differently than their Hash counterparts.
# Generally, methods that use Entry Order will use the sort order of the keys instead.
# For example:
#
# h = Hash.new
# h[:b] = 1
# h[:a] = 2
# h.first # => [:b, 1]
#
# sh = SortedHash.new
# sh[:b] = 1
# sh[:a] = 2
# sh.first # => [:a, 2]
#
class SortedHash
include Enumerable
extend Forwardable

# Initializes a new instance of the SortedHash class.
#
# @param hash [Hash] The initial key-value pairs for the SortedHash.
# @param default_value [Object] The default value for the SortedHash.
# @param block [Proc] The block to call to calculate the default value.
# @param load_factor [Integer] The load factor for the SortedHash.
# @yield [Proc] The block to call to calculate the default value.
def initialize(default_value = nil, load_factor: SortedArray::DEFAULT_LOAD_FACTOR)
raise ArgumentError, "cannot specify both default value and block" if !default_value.nil? && block_given?

Expand Down

0 comments on commit af4e8f3

Please sign in to comment.