Class: Hash

Inherits:
Object
  • Object
show all
Defined in:
lib/shoes/inspect.rb

Instance Method Summary collapse

Instance Method Details

#inspect(hits = {}) ⇒ Object


54
55
56
57
58
59
60
61
62
63
# File 'lib/shoes/inspect.rb', line 54

def inspect(hits = {})
    return "{...}" if hits[self]
    hits[self] = true
    mappings = map do |k,v|
        key = k.method(:inspect).arity == 0 ? k.inspect : k.inspect(hits)
        val = v.method(:inspect).arity == 0 ? v.inspect : v.inspect(hits)
        "#{key} => #{val}"
    end
    "{ #{mappings.join(', ')} }"
end

#to_htmlObject


64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/shoes/inspect.rb', line 64

def to_html
  h = self
  Web.Bit {
    h5 "Pairs of Things"
    h1 "A Hash"
    unless h.empty?
      ul {
        h.each { |k, v| li { self << "<div class='hashkey'>#{HTML(k)}</div><div class='hashvalue'>#{HTML(v)}</div>" } }
      }
    end
  }
end