Sha256: 629430f9f4a8a908ed49ca64b4aaffb71fb3e45ab4080061e1de9286c020b58e
Contents?: true
Size: 790 Bytes
Versions: 11
Compression:
Stored size: 790 Bytes
Contents
require 'eg_helper' eg.helpers do def oids(v) sub = case v when Hash hh = {} v.each {|kk,vv| hh[kk] = oids(vv)} hh when Array v.map {|vv| oids(vv)} else v end n = {:class => v.class, :oid => v.__id__, :sub => sub} if v.respond_to?(:__id__) n[:oid] = v.__id__ else n[:oid] = 0 end n end end eg 'creation duplicates' do a1 = AngryHash[ :a => { :b => 1 }, :c => [ 1, :d, {:e => :f}, nil, true, false, 1.0, [ 'x', 'y' ] ] ] a2 = AngryHash[ a1 ] pp oids(a1) pp oids(a2) Assert(a1.a.__id__ != a2.a.__id__) Assert(a1.c[2].__id__ != a2.c[2].__id__) Assert(a1.c[7].__id__ != a2.c[7].__id__) end #eg 'cycle detection' do #end
Version data entries
11 entries across 11 versions & 2 rubygems