Sha256: 3d40ef59ed90f3c739e4a15f38cd478db5e371cd04b5d34d4421434d019bb14b

Contents?: true

Size: 932 Bytes

Versions: 58

Compression:

Stored size: 932 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)
    self.in?(another_object) ? self : nil
  end
end

Version data entries

58 entries across 56 versions & 9 rubygems

Version Path
files.com-1.0.55 docs/vendor/bundle/ruby/2.5.0/gems/activesupport-5.0.7.1/lib/active_support/core_ext/object/inclusion.rb
activesupport-5.0.7.2 lib/active_support/core_ext/object/inclusion.rb
activesupport-5.0.7.1 lib/active_support/core_ext/object/inclusion.rb
activesupport-5.0.7 lib/active_support/core_ext/object/inclusion.rb
activesupport-5.0.6 lib/active_support/core_ext/object/inclusion.rb
activesupport-5.0.6.rc1 lib/active_support/core_ext/object/inclusion.rb
activesupport-5.0.5 lib/active_support/core_ext/object/inclusion.rb
activesupport-5.0.5.rc2 lib/active_support/core_ext/object/inclusion.rb
activesupport-5.0.5.rc1 lib/active_support/core_ext/object/inclusion.rb
tdiary-5.0.5 vendor/bundle/gems/tdiary-5.0.4/vendor/bundle/gems/activesupport-5.0.2/lib/active_support/core_ext/object/inclusion.rb
tdiary-5.0.5 vendor/bundle/gems/activesupport-5.0.2/lib/active_support/core_ext/object/inclusion.rb
activesupport-5.0.4 lib/active_support/core_ext/object/inclusion.rb
activesupport-5.0.4.rc1 lib/active_support/core_ext/object/inclusion.rb
activesupport-5.0.3 lib/active_support/core_ext/object/inclusion.rb
enju_leaf-1.2.1 vendor/bundle/ruby/2.3/gems/activesupport-5.0.2/lib/active_support/core_ext/object/inclusion.rb
lazy_record-0.2.1 vendor/bundle/gems/activesupport-5.0.2/lib/active_support/core_ext/object/inclusion.rb
lazy_record-0.2.0 vendor/bundle/gems/activesupport-5.0.2/lib/active_support/core_ext/object/inclusion.rb
lazy_record-0.1.9 vendor/bundle/gems/activesupport-5.0.2/lib/active_support/core_ext/object/inclusion.rb
lazy_record-0.1.8 vendor/bundle/gems/activesupport-5.0.2/lib/active_support/core_ext/object/inclusion.rb
lazy_record-0.1.7 vendor/bundle/gems/activesupport-5.0.2/lib/active_support/core_ext/object/inclusion.rb