Sha256: a7ed59c3e6037ca3b279d31d99a9b2d4b710217b3446e12124c9af9360f43519

Contents?: true

Size: 409 Bytes

Versions: 368

Compression:

Stored size: 409 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 if blank?

    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

368 entries across 368 versions & 4 rubygems

Version Path
eac_ruby_utils-0.124.0 lib/eac_ruby_utils/patches/object/if_present.rb
eac_tools-0.97.2 sub/eac_ruby_utils/lib/eac_ruby_utils/patches/object/if_present.rb
eac_ruby_utils-0.123.0 lib/eac_ruby_utils/patches/object/if_present.rb
eac_ruby_utils-0.121.0 lib/eac_ruby_utils/patches/object/if_present.rb
eac_ruby_utils-0.120.0 lib/eac_ruby_utils/patches/object/if_present.rb
eac_tools-0.76.1 sub/eac_ruby_utils/lib/eac_ruby_utils/patches/object/if_present.rb
eac_tools-0.76.0 sub/eac_ruby_utils/lib/eac_ruby_utils/patches/object/if_present.rb
eac_tools-0.75.2 sub/eac_ruby_utils/lib/eac_ruby_utils/patches/object/if_present.rb
eac_ruby_utils-0.119.2 lib/eac_ruby_utils/patches/object/if_present.rb
eac_tools-0.75.1 sub/eac_ruby_utils/lib/eac_ruby_utils/patches/object/if_present.rb
eac_tools-0.75.0 sub/eac_ruby_utils/lib/eac_ruby_utils/patches/object/if_present.rb
eac_ruby_utils-0.119.1 lib/eac_ruby_utils/patches/object/if_present.rb
eac_tools-0.74.1 sub/eac_ruby_utils/lib/eac_ruby_utils/patches/object/if_present.rb
eac_tools-0.74.0 sub/eac_ruby_utils/lib/eac_ruby_utils/patches/object/if_present.rb
eac_tools-0.73.0 sub/eac_ruby_utils/lib/eac_ruby_utils/patches/object/if_present.rb
eac_ruby_utils-0.119.0 lib/eac_ruby_utils/patches/object/if_present.rb
eac_tools-0.72.0 sub/eac_ruby_utils/lib/eac_ruby_utils/patches/object/if_present.rb
eac_ruby_utils-0.118.1 lib/eac_ruby_utils/patches/object/if_present.rb
eac_ruby_utils-0.118.0 lib/eac_ruby_utils/patches/object/if_present.rb
eac_tools-0.70.1 sub/eac_ruby_utils/lib/eac_ruby_utils/patches/object/if_present.rb