Sha256: 88a1bc730ff346a6fa81d40d3411ecb3e119ec9108333cf3408d562022f79197
Contents?: true
Size: 467 Bytes
Versions: 18
Compression:
Stored size: 467 Bytes
Contents
# -*- encoding : utf-8 -*- module Dao class PathMap < ::Map def to_json(*args, &block) as_json.to_json(*args, &block) end def as_json inject(Map.new){|json, kv| json.update(json_key_for(kv.first) => kv.last)} end def json_key_for(key) Array(key).join('.').gsub(/\.(\d+)(\.)?/, '[\1]\2') end end end if $0 == __FILE__ pm = Dao::PathMap.new pm[[:array, 0, :key]] = 'value' pm[[:key]] = 'value' p pm.as_json end
Version data entries
18 entries across 18 versions & 1 rubygems