Sha256: 7d44fa2e19c2e7727df5e422358d94b3abb49886272cab9c5ef5c4677dda9264

Contents?: true

Size: 300 Bytes

Versions: 13

Compression:

Stored size: 300 Bytes

Contents

# frozen_string_literal: true

require 'active_support/core_ext/object/blank'

class Object
  # @return +block.call(self)+ if +self+ is present, +default_value+ otherwise.
  def if_present(default_value = nil)
    return default_value unless present?

    block_given? ? yield(self) : self
  end
end

Version data entries

13 entries across 13 versions & 2 rubygems

Version Path
ehbrs-tools-0.3.0 vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/object/if_present.rb
eac_ruby_utils-0.23.0 lib/eac_ruby_utils/patches/object/if_present.rb
eac_ruby_utils-0.22.0 lib/eac_ruby_utils/patches/object/if_present.rb
eac_ruby_utils-0.21.0 lib/eac_ruby_utils/patches/object/if_present.rb
eac_ruby_utils-0.20.0 lib/eac_ruby_utils/patches/object/if_present.rb
eac_ruby_utils-0.19.0 lib/eac_ruby_utils/patches/object/if_present.rb
eac_ruby_utils-0.18.1 lib/eac_ruby_utils/patches/object/if_present.rb
eac_ruby_utils-0.18.0 lib/eac_ruby_utils/patches/object/if_present.rb
eac_ruby_utils-0.17.0 lib/eac_ruby_utils/patches/object/if_present.rb
eac_ruby_utils-0.16.0 lib/eac_ruby_utils/patches/object/if_present.rb
eac_ruby_utils-0.15.0 lib/eac_ruby_utils/patches/object/if_present.rb
eac_ruby_utils-0.14.0 lib/eac_ruby_utils/patches/object/if_present.rb
eac_ruby_utils-0.13.0 lib/eac_ruby_utils/patches/object/if_present.rb