Module: Common::Util

Defined in:
lib/common/util.rb

Class Method Summary collapse

Class Method Details

.write_file(file_name, content, append = false) ⇒ Object



3
4
5
6
7
8
9
# File 'lib/common/util.rb', line 3

def self.write_file(file_name, content, append=false)
  File.open(file_name, append ? "a" : "w") do |f|
    f.write(content)
  end
rescue Exception => ex
  write_file(file_name, content.force_encoding('UTF-8'), append)
end

.yaml(hash) ⇒ Object



11
12
13
14
15
# File 'lib/common/util.rb', line 11

def self.yaml(hash)
  method = hash.respond_to?(:ya2yaml) ? :ya2yaml : :to_yaml
  string = hash.deep_stringify_keys.send(method)
  string.gsub("!ruby/symbol ", ":").sub("---","").split("\n").map(&:rstrip).join("\n").strip
end