Class: SimpleSet::SetHash

Inherits:
ActiveSupport::OrderedHash
  • Object
show all
Defined in:
lib/simple_set/set_hash.rb

Instance Method Summary collapse

Constructor Details

#initialize(args = []) ⇒ SetHash

Returns a new instance of SetHash.



3
4
5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/simple_set/set_hash.rb', line 3

def initialize(args = [])
  super()

  args = if args.is_a?(Hash) then
    args.each { |k,v| set_value_for_reverse_lookup(k, v) }
  elsif args.is_a?(Array) && !args.first.is_a?(Array) then
    args.each_with_index.map { |x,y| [x, 2**y] }
  else
    raise Exception.new()
  end
  args.each { |e| set_value_for_reverse_lookup(e[0], e[1]) }

  freeze
end