Sha256: f94b19b75c342c89d00523d8b73bb77a630adf28485fd20022c73e037a094eb9

Contents?: true

Size: 928 Bytes

Versions: 103

Compression:

Stored size: 928 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

103 entries across 98 versions & 13 rubygems

Version Path
activesupport-4.2.11.3 lib/active_support/core_ext/object/inclusion.rb
activesupport-4.2.11.2 lib/active_support/core_ext/object/inclusion.rb
cocoapods-dependency-html-0.0.2 vendor/bundle/gems/activesupport-4.2.11.1/lib/active_support/core_ext/object/inclusion.rb
cocoapods-dependency-html-0.0.1 vendor/bundle/gems/activesupport-4.2.11.1/lib/active_support/core_ext/object/inclusion.rb
activesupport-4.2.11.1 lib/active_support/core_ext/object/inclusion.rb
activesupport-4.2.11 lib/active_support/core_ext/object/inclusion.rb
activesupport-4.2.10 lib/active_support/core_ext/object/inclusion.rb
activesupport-4.2.10.rc1 lib/active_support/core_ext/object/inclusion.rb
a_little_less-0.2.4 lib/vendor/rails_inclusion.rb
a_little_less-0.2.3 lib/vendor/rails_inclusion.rb
a_little_less-0.2.2 lib/vendor/rails_inclusion.rb
a_little_less-0.2.1 lib/vendor/rails_inclusion.rb
activesupport-4.2.9 lib/active_support/core_ext/object/inclusion.rb
activesupport-4.2.9.rc2 lib/active_support/core_ext/object/inclusion.rb
activesupport-4.2.9.rc1 lib/active_support/core_ext/object/inclusion.rb
enju_leaf-1.2.1 vendor/bundle/ruby/2.3/gems/activesupport-4.2.8/lib/active_support/core_ext/object/inclusion.rb
activesupport-4.2.8 lib/active_support/core_ext/object/inclusion.rb
activesupport-4.2.8.rc1 lib/active_support/core_ext/object/inclusion.rb
activesupport-4.2.7.1 lib/active_support/core_ext/object/inclusion.rb
activesupport-4.2.7 lib/active_support/core_ext/object/inclusion.rb