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.40.4 lib/puppeteer/if_present.rb
puppeteer-ruby-0.40.3 lib/puppeteer/if_present.rb
puppeteer-ruby-0.40.2 lib/puppeteer/if_present.rb
puppeteer-ruby-0.40.1 lib/puppeteer/if_present.rb
puppeteer-ruby-0.40.0 lib/puppeteer/if_present.rb
puppeteer-ruby-0.39.0 lib/puppeteer/if_present.rb
puppeteer-ruby-0.38.0 lib/puppeteer/if_present.rb
puppeteer-ruby-0.37.4 lib/puppeteer/if_present.rb
puppeteer-ruby-0.37.3 lib/puppeteer/if_present.rb
puppeteer-ruby-0.37.2 lib/puppeteer/if_present.rb
puppeteer-ruby-0.37.1 lib/puppeteer/if_present.rb
puppeteer-ruby-0.37.0 lib/puppeteer/if_present.rb
puppeteer-ruby-0.36.0 lib/puppeteer/if_present.rb
puppeteer-ruby-0.35.1 lib/puppeteer/if_present.rb
puppeteer-ruby-0.35.0 lib/puppeteer/if_present.rb
puppeteer-ruby-0.34.3 lib/puppeteer/if_present.rb
puppeteer-ruby-0.34.2 lib/puppeteer/if_present.rb
puppeteer-ruby-0.34.1 lib/puppeteer/if_present.rb
puppeteer-ruby-0.34.0 lib/puppeteer/if_present.rb
puppeteer-ruby-0.33.0 lib/puppeteer/if_present.rb