Class: String

Inherits:
Object
  • Object
show all
Defined in:
lib/i18n_translation_spawner/string.rb

Overview

> “a.b.c”.to_hash(“Some value”)

> value”}}

Instance Method Summary collapse

Instance Method Details

#to_hash(val = nil) ⇒ Object



5
6
7
8
9
10
11
12
13
# File 'lib/i18n_translation_spawner/string.rb', line 5

def to_hash(val=nil)
  keys = split('.')
  Hash.new.tap do |hsh|
    while k = keys.shift do
      hsh[k] = keys.empty? ? val : Hash.new
      hsh = hsh[k]
    end
  end
end