instance method
in?
Ruby on Rails edge
Since v3.1.12Signature
in?(another_object)
Returns true if this object is included in the argument.
When argument is a `Range`, `#cover?` is used to properly handle inclusion
check within open ranges. Otherwise, argument must be any object which responds
to `#include?`. Usage:
```ruby
characters = ["Konata", "Kagami", "Tsukasa"]
"Konata".in?(characters) # => true
```
For non `Range` arguments, this will throw an `ArgumentError` if the argument
doesn't respond to `#include?`.
: (untyped) -> bool
Parameters
-
another_objectreq
Source
# File activesupport/lib/active_support/core_ext/object/inclusion.rb, line 18
def in?(another_object)
case another_object
when Range
another_object.cover?(self)
else
another_object.include?(self)
end
rescue NoMethodError
raise ArgumentError.new("The parameter passed to #in? must respond to #include?")
end
Defined in activesupport/lib/active_support/core_ext/object/inclusion.rb line 18
· View on GitHub
· Improve this page
· Find usages on GitHub
Defined in Object