Module: Hamster

Defined in:
lib/nrser/gem_ext/hamster/set.rb,
lib/nrser/gem_ext/hamster.rb,
lib/nrser/gem_ext/hamster/hash.rb,
lib/nrser/gem_ext/hamster/vector.rb,
lib/nrser/gem_ext/hamster/sorted_set.rb

Overview

Namespace

Defined Under Namespace

Classes: Hash, Set, SortedSet, Vector

Class Method Summary collapse

Class Method Details

.to_mutable(obj) ⇒ Object

def self.regrow each_pair: ::Hash, each_index: ::Array, each:



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/nrser/gem_ext/hamster.rb', line 12

def self.to_mutable obj
  if obj.respond_to? :to_mutable
    obj.to_mutable
    
  elsif ::Array === obj
    obj.map { |e| to_mutable e }
    
  elsif ::Hash === obj
    obj.each_with_object( {} ) { |(k, v), h|
      h[ to_mutable k ] = to_mutable v
    }
    
  elsif ::SortedSet === obj
    ::SortedSet.new obj.map { |m| to_mutable m }
    
  elsif ::Set === obj
    ::Set.new obj.map { |m| to_mutable m }
    
  else
    obj
    
  end
end