Skip to content
This repository
tree: c6ef49f461
file 26 lines (25 sloc) 0.863 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
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
Something went wrong with that request. Please try again.