Class: Hash

Inherits:
Object show all
Defined in:
lib/lorj/compat.rb

Overview

Redefine string representation of Hash

Instance Method Summary collapse

Instance Method Details

#to_sObject



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/lorj/compat.rb', line 59

def to_s
  local = []
  each do |a, b|
    if a.is_a?(String)
      k = "\"#{a}\""
    elsif a.is_a?(Symbol)
      k = ":#{a}"
    else
      k = a.to_s
    end

    if b.is_a?(String)
      v = "\"#{b}\""
    elsif b.is_a?(Symbol)
      v = ":#{b}"
    else
      v = b.to_s
    end
    local << "#{k}=>#{v}"
  end
  '{' + local.join(', ') + '}'
end