Class: IceNine::RecursionGuard::ObjectSet
- Inherits:
-
IceNine::RecursionGuard
- Object
- IceNine::RecursionGuard
- IceNine::RecursionGuard::ObjectSet
- Defined in:
- lib/ice_nine/support/recursion_guard.rb
Overview
Protects against infinite recursion by never yielding with the same object more than once.
Instance Method Summary collapse
-
#guard(object) ⇒ Object
Guard against recursively calling a block with the same object.
-
#initialize ⇒ undefined
constructor
Initialize a recursion guard.
Constructor Details
#initialize ⇒ undefined
Initialize a recursion guard
17 18 19 |
# File 'lib/ice_nine/support/recursion_guard.rb', line 17 def initialize @object_ids = {} end |
Instance Method Details
#guard(object) ⇒ Object
Guard against recursively calling a block with the same object
32 33 34 35 36 37 |
# File 'lib/ice_nine/support/recursion_guard.rb', line 32 def guard(object) caller_object_id = object.__id__ return object if @object_ids.key?(caller_object_id) @object_ids[caller_object_id] = nil yield end |