lib/ice_nine/support/recursion_guard.rb
# Guard against recursively calling a block with the same object
#
# @example
#   recursion_guard = IceNine::RecursionGuard::ObjectSet.new
#   recursion_guard.guard(object) do
#     logic_which_may_be_recursively_called_with_object(recursion_guard)
#   end
#
# @param [Object] object
#
# @return [Object]
Guard against recursively calling a block with the same object
Guard against recursively calling a block with the same object
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
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
Guard against recursively calling a block with the same object
Guard against recursively calling a block with the same object
None
Object
object
<not_specific>
<not_specific>
None
example
recursion_guard = IceNine::RecursionGuard::ObjectSet.new recursion_guard.guard(object) do logic_which_may_be_recursively_called_with_object(recursion_guard) end
recursion_guard = IceNine :: RecursionGuard :: ObjectSet . new recursion_guard . guard ( object ) do logic_which_may_be_recursively_called_with_object ( recursion_guard ) end