Module: Bixby::Debug
- Defined in:
- lib/bixby-common/util/debug.rb
Class Method Summary collapse
- .indent_lines(str, indent = "\t") ⇒ Object
-
.pretty_hash(hash) ⇒ String
Pretty print a hash.
-
.pretty_str(str) ⇒ Object
Simple helper for use in to_s methods.
Class Method Details
.indent_lines(str, indent = "\t") ⇒ Object
42 43 44 |
# File 'lib/bixby-common/util/debug.rb', line 42 def self.indent_lines(str, indent="\t") str.gsub(/\n/, "\n#{indent}") end |
.pretty_hash(hash) ⇒ String
Pretty print a hash
31 32 33 34 35 36 37 38 39 40 |
# File 'lib/bixby-common/util/debug.rb', line 31 def self.pretty_hash(hash) return "{}" if hash.empty? s = [ "\n\t{" ] l = hash.keys.max_by{ |k| k.length }.length + 1 # length of longest key so we can align values hash.keys.each{ |k| s << (" %s%s=> %s," % [k, " "*(l-k.length), hash[k].inspect]) } s << "}" return s.join("\n\t") end |
.pretty_str(str) ⇒ Object
Simple helper for use in to_s methods
8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/bixby-common/util/debug.rb', line 8 def self.pretty_str(str) if str.nil? then "nil" elsif str.empty? then '""' elsif str.include? "\n" then "<<-EOF\n" + str + "\nEOF" else '"' + str + '"' end end |