Sha256: 530729a3afcc0f0f502138fbb6bbcf0ff241a53fa6a590d6f120b16733234bed

Contents?: true

Size: 371 Bytes

Versions: 255

Compression:

Stored size: 371 Bytes

Contents

# frozen_string_literal: true

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

    block_given? ? yield(self) : self
  end

  # @return +yield+ if +self+ is nil, +self+ otherwise.
  def if_nil
    return yield if nil? && block_given?

    self
  end
end

Version data entries

255 entries across 255 versions & 4 rubygems

Version Path
eac_ruby_utils-0.107.1 lib/eac_ruby_utils/patches/object/if_nil.rb
eac_tools-0.44.0 sub/eac_ruby_utils/lib/eac_ruby_utils/patches/object/if_nil.rb
eac_tools-0.43.0 sub/eac_ruby_utils/lib/eac_ruby_utils/patches/object/if_nil.rb
eac_ruby_utils-0.107.0 lib/eac_ruby_utils/patches/object/if_nil.rb
eac_tools-0.42.0 sub/eac_ruby_utils/lib/eac_ruby_utils/patches/object/if_nil.rb
eac_tools-0.41.0 sub/eac_ruby_utils/lib/eac_ruby_utils/patches/object/if_nil.rb
eac_tools-0.40.0 sub/eac_ruby_utils/lib/eac_ruby_utils/patches/object/if_nil.rb
eac_tools-0.39.0 sub/eac_ruby_utils/lib/eac_ruby_utils/patches/object/if_nil.rb
eac_ruby_utils-0.106.1 lib/eac_ruby_utils/patches/object/if_nil.rb
eac_ruby_utils-0.106.0 lib/eac_ruby_utils/patches/object/if_nil.rb
eac_tools-0.38.0 sub/eac_ruby_utils/lib/eac_ruby_utils/patches/object/if_nil.rb
eac_tools-0.37.2 sub/eac_ruby_utils/lib/eac_ruby_utils/patches/object/if_nil.rb
eac_ruby_utils-0.105.0 lib/eac_ruby_utils/patches/object/if_nil.rb
eac_tools-0.37.1 sub/eac_ruby_utils/lib/eac_ruby_utils/patches/object/if_nil.rb
eac_tools-0.37.0 sub/eac_ruby_utils/lib/eac_ruby_utils/patches/object/if_nil.rb
eac_tools-0.36.1 sub/eac_ruby_utils/lib/eac_ruby_utils/patches/object/if_nil.rb
eac_tools-0.36.0 sub/eac_ruby_utils/lib/eac_ruby_utils/patches/object/if_nil.rb
eac_tools-0.35.0 sub/eac_ruby_utils/lib/eac_ruby_utils/patches/object/if_nil.rb
eac_tools-0.34.0 sub/eac_ruby_utils/lib/eac_ruby_utils/patches/object/if_nil.rb
eac_tools-0.33.0 sub/eac_ruby_utils/lib/eac_ruby_utils/patches/object/if_nil.rb