module Utilities
Public Class Methods
deep_traverse_hash(obj, &block)
click to toggle source
Traverse each key, value of the hash and any nested hashes (including those in arrays) E.G. to deep transfrom do:
deep_traverse_hash(obj) { |hash, k, v| hash[k] = v.upcase if v.is_a?(String) }
# File lib/util/util.rb, line 5 def self.deep_traverse_hash(obj, &block) if obj.is_a? Array obj.each { |val| deep_traverse_hash(val, &block) } elsif obj.is_a?(Hash) obj.each_pair do |k,v| deep_traverse_hash(v, &block) block.call(obj, k, v) end end end
remove_enclosing_quotes(str)
click to toggle source
# File lib/util/util.rb, line 16 def self.remove_enclosing_quotes(str) quote_chars = ['"', '\''] quote_chars.each do |quote_char| return str[1..-2] if str.start_with?(quote_char) && str.end_with?(quote_char) end return str end