Class: CircularObjectContainer
Instance Method Summary collapse
- #blockify_elements(&block) ⇒ Object
- #circular?(path = [], stack = {}, rtn = [false]) ⇒ Boolean
-
#dup ⇒ Object
get the innards and discard container.
- #find_element_path(path = [], done = [false], &block) ⇒ Object
- #find_element_paths(path = [], paths = [], &block) ⇒ Object
-
#id ⇒ Object
get the original object_id.
-
#initialize(obj) ⇒ CircularObjectContainer
constructor
A new instance of CircularObjectContainer.
- #scan_elements(&block) ⇒ Object
- #taboo? ⇒ Boolean
- #type ⇒ Object
Constructor Details
#initialize(obj) ⇒ CircularObjectContainer
Returns a new instance of CircularObjectContainer.
299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 |
# File 'lib/blockify.rb', line 299 def initialize(obj) @id = obj.object_id if obj.respond_to? :each_pair @obj = obj.class.new # create a blank slate obj.each_pair do |key,val| if val.respond_to? :each @obj[key] = val.class.new # go no further else tval = val.dup rescue val @obj[key] = tval end end self.instance_eval do # yes we want a singleton method here! def each_pair(&block) @obj.each_pair &block end def each(&block) @obj.each &block end def [](key) @obj[key] end end elsif obj.respond_to? :each @obj = obj.class.new # create a blank slate obj.each do |val| if val.respond_to? :each @obj.push val.class.new else tval = val.dup rescue val @obj.push tval end end self.instance_eval do # yes we want a singleton method here! def each(&block) @obj.each &block end def [](idx) @obj[idx] end end else @obj = obj.dup rescue obj end @obj.freeze self.freeze self end |
Instance Method Details
#blockify_elements(&block) ⇒ Object
362 363 364 |
# File 'lib/blockify.rb', line 362 def blockify_elements(&block) @obj.dup.blockify_elements(&block) end |
#circular?(path = [], stack = {}, rtn = [false]) ⇒ Boolean
359 360 361 |
# File 'lib/blockify.rb', line 359 def circular? (path = [], stack = {}, rtn = [false]) return rtn.first end |
#dup ⇒ Object
get the innards and discard container
353 354 355 |
# File 'lib/blockify.rb', line 353 def dup # get the innards and discard container @obj.dup rescue @obj end |
#find_element_path(path = [], done = [false], &block) ⇒ Object
365 366 367 |
# File 'lib/blockify.rb', line 365 def find_element_path(path=[],done=[false], &block) @obj.dup.find_element_path(path,done, &block) end |
#find_element_paths(path = [], paths = [], &block) ⇒ Object
368 369 370 |
# File 'lib/blockify.rb', line 368 def find_element_paths(path=[],paths=[], &block) @obj.dup.find_element_paths(path,paths, &block) end |
#id ⇒ Object
get the original object_id
347 348 349 |
# File 'lib/blockify.rb', line 347 def id # get the original object_id @id end |
#scan_elements(&block) ⇒ Object
371 372 373 |
# File 'lib/blockify.rb', line 371 def scan_elements(&block) @obj.dup.scan_elements(&block) end |
#taboo? ⇒ Boolean
356 357 358 |
# File 'lib/blockify.rb', line 356 def taboo? true end |
#type ⇒ Object
350 351 352 |
# File 'lib/blockify.rb', line 350 def type @obj.class end |