Method: Concurrent::IVar#try_set

Defined in:
lib/concurrent/ivar.rb

#try_set(value = NULL) { ... } ⇒ Boolean

Attempt to set the ‘IVar` with the given value or block. Return a boolean indicating the success or failure of the set operation.

Parameters:

  • value (Object) (defaults to: NULL)

    the value to store in the ‘IVar`

Yields:

  • A block operation to use for setting the value

Returns:

  • (Boolean)

    true if the value was set else false

Raises:



144
145
146
147
148
149
# File 'lib/concurrent/ivar.rb', line 144

def try_set(value = NULL, &block)
  set(value, &block)
  true
rescue MultipleAssignmentError
  false
end