Module: Puppeteer::IfPresent
- Included in:
- Browser, ElementHandle, ExecutionContext, ExecutionContext::JavaScriptFunction, FrameManager, JSHandle, LifecycleWatcher, NetworkManager, Page, Request, Response
- Defined in:
- lib/puppeteer/if_present.rb
Instance Method Summary collapse
-
#if_present(target, &block) ⇒ Object
Similar to #try in ActiveSupport::CoreExt.
Instance Method Details
#if_present(target, &block) ⇒ Object
Similar to #try in ActiveSupport::CoreExt.
Evaluate block with the target, only if target is not nil. Returns nil if target is nil.
if_present(params) do |target|
Point.new(target['x'], target['y'])
end
12 13 14 15 16 17 |
# File 'lib/puppeteer/if_present.rb', line 12 def if_present(target, &block) raise ArgumentError.new('block must be provided for #if_present') if block.nil? return nil if target.nil? block.call(target) end |