module HashHelper
Ruby Hash utility module
Public Instance Methods
add_hash_if_array(a1, b1)
click to toggle source
submethod used by add_hash2_to_hash1 if type Array
# File lib/hash_helper.rb, line 14 def add_hash_if_array(a1, b1) a1 = a1.enum_for(:each_with_index).collect do |m, index| if %w[Array Hash].include?(m.class.name) add_hash2_to_hash1(a1[index], b1[index]) else m + b1[index] end end a1 end
add_hash_if_hash(a1, b1)
click to toggle source
submethod used by add_hash2_to_hash1 if type Hash
# File lib/hash_helper.rb, line 26 def add_hash_if_hash(a1, b1) a1.each do |k, _v| if %w[Array Hash].include?(a1[k].class.name) a1[k] = add_hash2_to_hash1(a1[k], b1[k]) else a1[k] += b1[k] end end end
tokenize(str)
click to toggle source
# File lib/hash_helper.rb, line 7 def tokenize(str) # extract words + nums str.scan(/[0-9.e-]+|\w+/) end