Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there an inversish method for `Array#include?`?

Tags:

ruby

I've always wondered if there is an inverse method for include?. So that given:

str = "a"
ary = ["a", "b", "c"]

I can check if the string is in the array rather than if the array contains the string. Something like:

str.in?(ary)

I can't think of a situation where this is necessary, but often I think from that direction rather than the other way around.

like image 659
Flip Avatar asked Jan 16 '16 12:01

Flip


1 Answers

There is no such method in Ruby itself, but there is such method in Rails - Object#in

like image 85
sawa Avatar answered Oct 07 '22 17:10

sawa