Sha256: 86cfcc65742402d5c7c4c606af56bbb3b03a5177ffddf4f5782152cd243edd6f

Contents?: true

Size: 415 Bytes

Versions: 20

Compression:

Stored size: 415 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

  # @return +yield+ if +self+ is blank.
  def if_blank
    return yield if blank? && block_given?

    self
  end
end

Version data entries

20 entries across 20 versions & 2 rubygems

Version Path
ehbrs-tools-0.11.0 vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/object/if_present.rb
eac_ruby_utils-0.34.0 lib/eac_ruby_utils/patches/object/if_present.rb
eac_ruby_utils-0.33.1 lib/eac_ruby_utils/patches/object/if_present.rb
eac_ruby_utils-0.33.0 lib/eac_ruby_utils/patches/object/if_present.rb
ehbrs-tools-0.10.0 vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/object/if_present.rb
eac_ruby_utils-0.32.1 lib/eac_ruby_utils/patches/object/if_present.rb
eac_ruby_utils-0.32.0 lib/eac_ruby_utils/patches/object/if_present.rb
ehbrs-tools-0.9.0 vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/object/if_present.rb
eac_ruby_utils-0.31.0 lib/eac_ruby_utils/patches/object/if_present.rb
ehbrs-tools-0.7.0 vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/object/if_present.rb
eac_ruby_utils-0.30.0 lib/eac_ruby_utils/patches/object/if_present.rb
ehbrs-tools-0.6.0 vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/object/if_present.rb
eac_ruby_utils-0.29.0 lib/eac_ruby_utils/patches/object/if_present.rb
eac_ruby_utils-0.28.0 lib/eac_ruby_utils/patches/object/if_present.rb
ehbrs-tools-0.5.0 vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/object/if_present.rb
eac_ruby_utils-0.27.0 lib/eac_ruby_utils/patches/object/if_present.rb
eac_ruby_utils-0.26.0 lib/eac_ruby_utils/patches/object/if_present.rb
eac_ruby_utils-0.25.0 lib/eac_ruby_utils/patches/object/if_present.rb
ehbrs-tools-0.3.1 vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/object/if_present.rb
eac_ruby_utils-0.24.1 lib/eac_ruby_utils/patches/object/if_present.rb