Sha256: e30cc8db6ac7d542e147d1ff9ac4d05ef09abcbe84995f719a167c6b15f4a809

Contents?: true

Size: 798 Bytes

Versions: 10

Compression:

Stored size: 798 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?(*args)
    if args.length > 1
      puts "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

10 entries across 10 versions & 1 rubygems

Version Path
droiuby-0.3.6 lib/droiuby/support/object/inclusion.rb
droiuby-0.3.5 lib/droiuby/support/object/inclusion.rb
droiuby-0.3.4 lib/droiuby/support/object/inclusion.rb
droiuby-0.3.3 lib/droiuby/support/object/inclusion.rb
droiuby-0.3.2 lib/droiuby/support/object/inclusion.rb
droiuby-0.3.1 lib/droiuby/support/object/inclusion.rb
droiuby-0.3.0 lib/droiuby/support/object/inclusion.rb
droiuby-0.2.9 lib/droiuby/support/object/inclusion.rb
droiuby-0.2.8 lib/droiuby/support/object/inclusion.rb
droiuby-0.2.7 lib/droiuby/support/object/inclusion.rb