Sha256: 6148d29e0428ad3a0945e3bb67d4aadd695e0901bfcf555d7f767fa84b4dd513
Contents?: true
Size: 1.49 KB
Versions: 4
Compression:
Stored size: 1.49 KB
Contents
= OpenCascade The reason this class is labeled "cascade", is that every internal Hash is transformed into an OpenCascade dynamically upon access. This makes it easy to create _cascading_ references. h = { :x => { :y => { :z => 1 } } } c = OpenCascade[h] assert c.x.y.z == 1 As soon as you access a node it automatically becomes an OpenCascade. c = OpenCascade.new assert(OpenCascade === c.r) assert(OpenCascade === c.a.b) But if you set a node, then that will be it's value. c.a.b = 4 assert c.a.b == 4 To query a node without causing the auto-creation of an OpenCasade object, use the ?-mark. assert c.a.z? == nil OpenCascade also transforms Hashes within Arrays. h = { :x=>[ {:a=>1}, {:a=>2} ], :y=>1 } c = OpenCascade[h] assert c.x.first.a == 1 assert c.x.last.a == 2 Like OpenObject, OpenCascade allows you to insert entries as array pairs. c = OpenCascade.new c << [:x,8] c << [:y,9] assert c.x == 8 assert c.y == 9 Finally, you can call methods ending in a !-mark to access the underlying hash (Note that these differ in behavior from the built-in !-methods). bk = c.map!{ |k,v| k.to_s.upcase } bk.sort.assert == ['X', 'Y'] So you can see that for the most an OpenCascade is just like OpenHash, but it allows us to conveniently build open sub-layers easily. Enumerable still works with OpenCascades too. h = {} c = OpenCascade[:a=>1,:b=>{:c=>3}] c.each do |k,v| h[k] = v end OpenCascade.assert === h[:b]
Version data entries
4 entries across 3 versions & 2 rubygems