class Hash

Redefine string representation of Hash

Public Instance Methods

to_s() click to toggle source
# 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