Method: Object#in?
- Defined in:
- activesupport/lib/active_support/core_ext/object/inclusion.rb
#in?(another_object) ⇒ Boolean
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:
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?.
15 16 17 18 19 20 21 22 23 24 |
# File 'activesupport/lib/active_support/core_ext/object/inclusion.rb', line 15 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 |