Module: RoSupport::Debug

Defined in:
lib/ro_support/debug.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object

ro is my name, ro_raise mean my raise



4
5
6
7
8
# File 'lib/ro_support/debug.rb', line 4

def self.included(base)
  base.send(:alias_method, :ro_raise, :eval)
  base.send(:alias_method, :ro_return, :eval)
  base.send(:alias_method, :ro_print, :eval)
end

Instance Method Details

#err(msg = 'error', opt = {output: []}) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/ro_support/debug.rb', line 21

def err(msg='error', opt={output: []})
  err = [""]
  err << msg
  err << "Instance Variables:"
  instance_variables.each do |ivar|
    err << "    #{ivar.to_s}: #{instance_variable_get(ivar)}"
  end

  print err.join("\n")

  <<-ERROR
  err = [""]

  err << ""
  err << "Output Variables:"
  err << ""
#{opt[:output]}.each do |var|
    if var.is_a?(String)
      err << "  \#{var}:\#{eval var}"
    end
  end

  raise err.join("\n") + "\n\n"
  ERROR
end

#valid(smth, opt = {}) ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/ro_support/debug.rb', line 47

def valid(smth, opt={})
  if opt[:valid?].nil?
    if smth.is_a?(Array) or smth.is_a?(Hash)
      is_valid = !smth.empty?
    else
      is_valid = !smth.nil?
    end

    if is_valid
      return smth
    else
      if opt[:output]
        err('return nil or empty', output: opt[:output])
      else
        err('return nil or empty')
      end
    end
  end
end

#vars(*lvars) ⇒ Object



11
12
13
14
15
16
17
18
19
# File 'lib/ro_support/debug.rb', line 11

def vars(*lvars)

  print_str = []
  lvars.each do |var_name|
    print_str << "p '#{var_name}:' + #{var_name}"
  end

  print_str.join(";")
end