Sha256: a9bf80ff0892353fc808da68d19daf04f30bb1a5d2d359aca0bb82de8eaf78cd

Contents?: true

Size: 830 Bytes

Versions: 2

Compression:

Stored size: 830 Bytes

Contents

class Object
  # Returns true if this object is included in the argument(s). Argument must be
  # any object which responds to +#include?+ or optionally, multiple arguments can be passed in. Usage:
  #
  #   characters = ['Konata', 'Kagami', 'Tsukasa']
  #   'Konata'.in?(characters) # => true
  #
  #   character = 'Konata'
  #   character.in?('Konata', 'Kagami', 'Tsukasa') # => true
  #
  # This will throw an ArgumentError if a single argument is passed in and it doesn't respond
  # to +#include?+.
  def in?(*args)
    if args.length > 1
      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

2 entries across 2 versions & 1 rubygems

Version Path
activesupport-4.0.0.rc1 lib/active_support/core_ext/object/inclusion.rb
activesupport-4.0.0.beta1 lib/active_support/core_ext/object/inclusion.rb