Top Level Namespace

Defined Under Namespace

Classes: Hash, MissingT

Instance Method Summary collapse

Instance Method Details

#hashify(segments, value) ⇒ Object

TODO: Should I feel about these ‘global’ helper functions?



4
5
6
7
8
9
10
11
12
# File 'lib/missing_t.rb', line 4

def hashify(segments, value)
  return {} if segments.empty?
  s, *rest = segments
  if rest.empty?
    { s => value }
  else
    { s => hashify(rest, value) }
  end
end


14
15
16
17
18
19
20
21
22
23
# File 'lib/missing_t.rb', line 14

def print_hash(h, level)
  h.each_pair do |k,v|
    if v.respond_to?(:each_pair)
      puts %(#{" " * (level*2)}#{k}:)
      print_hash(v, level+1)
    else
      puts %(#{" " * (level*2)}#{k}: #{v})
    end
  end
end