Sha256: 26296794dba84464b57a6adb4b68fa2cd82162801dae097920942defa053dfbd

Contents?: true

Size: 927 Bytes

Versions: 24

Compression:

Stored size: 927 Bytes

Contents

class Object
  # Returns true if this object is included in the argument. Argument must be
  # any object which responds to +#include?+. Usage:
  #
  #   characters = ["Konata", "Kagami", "Tsukasa"]
  #   "Konata".in?(characters) # => true
  #
  # This will throw an +ArgumentError+ if the argument doesn't respond
  # to +#include?+.
  def in?(another_object)
    another_object.include?(self)
  rescue NoMethodError
    raise ArgumentError.new("The parameter passed to #in? must respond to #include?")
  end

  # Returns the receiver if it's included in the argument otherwise returns +nil+.
  # Argument must be any object which responds to +#include?+. Usage:
  #
  #   params[:bucket_type].presence_in %w( project calendar )
  #
  # This will throw an +ArgumentError+ if the argument doesn't respond to +#include?+.
  #
  # @return [Object]
  def presence_in(another_object)
    in?(another_object) ? self : nil
  end
end

Version data entries

24 entries across 24 versions & 4 rubygems

Version Path
sigterm_extensions-0.0.4 lib/sigterm_extensions/core_ext/object/inclusion.rb
activesupport-5.1.7 lib/active_support/core_ext/object/inclusion.rb
activesupport-5.1.7.rc1 lib/active_support/core_ext/object/inclusion.rb
activesupport-5.1.6.2 lib/active_support/core_ext/object/inclusion.rb
activesupport-5.1.6.1 lib/active_support/core_ext/object/inclusion.rb
activesupport-5.1.6 lib/active_support/core_ext/object/inclusion.rb
tdiary-5.0.8 vendor/bundle/gems/activesupport-5.1.5/lib/active_support/core_ext/object/inclusion.rb
activesupport-5.1.5 lib/active_support/core_ext/object/inclusion.rb
activesupport-5.1.5.rc1 lib/active_support/core_ext/object/inclusion.rb
pract6-0.1.0 .gem/ruby/2.3.0/gems/activesupport-5.1.4/lib/active_support/core_ext/object/inclusion.rb
activesupport-5.1.4 lib/active_support/core_ext/object/inclusion.rb
activesupport-5.1.4.rc1 lib/active_support/core_ext/object/inclusion.rb
activesupport-5.1.3 lib/active_support/core_ext/object/inclusion.rb
activesupport-5.1.3.rc3 lib/active_support/core_ext/object/inclusion.rb
activesupport-5.1.3.rc2 lib/active_support/core_ext/object/inclusion.rb
activesupport-5.1.3.rc1 lib/active_support/core_ext/object/inclusion.rb
tdiary-5.0.5 vendor/bundle/gems/activesupport-5.1.2/lib/active_support/core_ext/object/inclusion.rb
activesupport-5.1.2 lib/active_support/core_ext/object/inclusion.rb
activesupport-5.1.2.rc1 lib/active_support/core_ext/object/inclusion.rb
activesupport-5.1.1 lib/active_support/core_ext/object/inclusion.rb