Module: Corefines::Object::In

Defined in:
lib/corefines/object.rb

Instance Method Summary collapse

Instance Method Details

#in?(other) ⇒ Boolean

Returns true if this object is included in the other object, false otherwise.

Examples:

Array

characters = ["Konata", "Kagami", "Tsukasa"]
"Konata".in?(characters) # => true

String

"f".in?("flynn") # => true
"x".in?("flynn") # => false

Raises:

  • ArgumentError if the other doesn't respond to #include?.


164
165
166
167
168
169
170
171
172
# File 'lib/corefines/object.rb', line 164

module In
  refine ::Object do
    def in?(other)
      other.include? self
    rescue NoMethodError
      fail ArgumentError, "The parameter passed to #in? must respond to #include?"
    end
  end
end