Sha256: 467ab87af650ca4240f58eaab8e73810ff64bb545ec1a2fb87701e5c42a3411d

Contents?: true

Size: 482 Bytes

Versions: 78

Compression:

Stored size: 482 Bytes

Contents

module Puppeteer::IfPresent
  # 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['target']) do |target|
  #   Point.new(target['x'], target['y'])
  # end
  # --------
  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
end

Version data entries

78 entries across 78 versions & 1 rubygems

Version Path
puppeteer-ruby-0.32.4 lib/puppeteer/if_present.rb
puppeteer-ruby-0.32.3 lib/puppeteer/if_present.rb
puppeteer-ruby-0.32.2 lib/puppeteer/if_present.rb
puppeteer-ruby-0.32.1 lib/puppeteer/if_present.rb
puppeteer-ruby-0.32.0 lib/puppeteer/if_present.rb
puppeteer-ruby-0.31.6 lib/puppeteer/if_present.rb
puppeteer-ruby-0.31.5 lib/puppeteer/if_present.rb
puppeteer-ruby-0.31.4 lib/puppeteer/if_present.rb
puppeteer-ruby-0.31.3 lib/puppeteer/if_present.rb
puppeteer-ruby-0.31.1 lib/puppeteer/if_present.rb
puppeteer-ruby-0.31.0 lib/puppeteer/if_present.rb
puppeteer-ruby-0.30.0 lib/puppeteer/if_present.rb
puppeteer-ruby-0.29.0 lib/puppeteer/if_present.rb
puppeteer-ruby-0.28.1 lib/puppeteer/if_present.rb
puppeteer-ruby-0.0.27 lib/puppeteer/if_present.rb
puppeteer-ruby-0.0.26 lib/puppeteer/if_present.rb
puppeteer-ruby-0.0.25 lib/puppeteer/if_present.rb
puppeteer-ruby-0.0.23 lib/puppeteer/if_present.rb
puppeteer-ruby-0.0.22 lib/puppeteer/if_present.rb
puppeteer-ruby-0.0.21 lib/puppeteer/if_present.rb