Sha256: 530729a3afcc0f0f502138fbb6bbcf0ff241a53fa6a590d6f120b16733234bed

Contents?: true

Size: 371 Bytes

Versions: 253

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

253 entries across 253 versions & 4 rubygems

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