Sha256: a19ca6a70f62e7ad1b8dab147c7eb0f71348afdfaf828079cf2b054203796868

Contents?: true

Size: 863 Bytes

Versions: 28

Compression:

Stored size: 863 Bytes

Contents

require 'active_support/deprecation'

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?(*args)
    if args.length > 1
      ActiveSupport::Deprecation.warn "Calling #in? with multiple arguments is" \
        " deprecated, please pass in an object that responds to #include? instead."
      args.include? self
    else
      another_object = args.first
      if another_object.respond_to? :include?
        another_object.include? self
      else
        raise ArgumentError.new 'The single parameter passed to #in? must respond to #include?'
      end
    end
  end
end

Version data entries

28 entries across 28 versions & 2 rubygems

Version Path
activesupport-4.0.13 lib/active_support/core_ext/object/inclusion.rb
activesupport-4.0.13.rc1 lib/active_support/core_ext/object/inclusion.rb
activesupport-4.0.11.1 lib/active_support/core_ext/object/inclusion.rb
activesupport-4.0.12 lib/active_support/core_ext/object/inclusion.rb
activesupport-4.0.11 lib/active_support/core_ext/object/inclusion.rb
activesupport-4.0.10 lib/active_support/core_ext/object/inclusion.rb
activesupport-4.0.10.rc2 lib/active_support/core_ext/object/inclusion.rb
activesupport-4.0.10.rc1 lib/active_support/core_ext/object/inclusion.rb
activesupport-4.0.9 lib/active_support/core_ext/object/inclusion.rb
activesupport-4.0.8 lib/active_support/core_ext/object/inclusion.rb
activesupport-4.0.7 lib/active_support/core_ext/object/inclusion.rb
activesupport-4.0.6 lib/active_support/core_ext/object/inclusion.rb
activesupport-4.0.6.rc3 lib/active_support/core_ext/object/inclusion.rb
activesupport-4.0.6.rc2 lib/active_support/core_ext/object/inclusion.rb
activesupport-4.0.6.rc1 lib/active_support/core_ext/object/inclusion.rb
activesupport-4.0.5 lib/active_support/core_ext/object/inclusion.rb
activesupport-4.0.4 lib/active_support/core_ext/object/inclusion.rb
activesupport-4.0.4.rc1 lib/active_support/core_ext/object/inclusion.rb
activesupport-4.0.3 lib/active_support/core_ext/object/inclusion.rb
activesupport-4.0.2 lib/active_support/core_ext/object/inclusion.rb