Module: DR::Utils

Extended by:
Utils
Included in:
Utils
Defined in:
lib/dr/base/utils.rb

Instance Method Summary collapse

Instance Method Details

#pretty_print(string, format: nil, pretty: false) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/dr/base/utils.rb', line 4

def pretty_print(string, format: nil, pretty: false)
  case format.to_s
  when "json"
    require 'json'
    return pretty_print(string.to_json)
  when "yaml"
    require "yaml"
    return pretty_print(string.to_yaml)
  end
  if pretty.to_s=="color"
    begin
      require 'ap'
      ap string
    rescue LoadError,NameError
      pretty_print(string,pretty:true)
    end
  elsif pretty
    require 'pp'
    pp string
  else
    puts string
  end
end