This blog is part of our Rails 5 series.
Rails 5 introduces Array Inquirer that wraps an array object and provides friendlier methods to check for the presence of elements that can be either a string or a symbol.
Array Inquirer also has
any? method to check for the presence of any of the passed arguments as elements in the array.
ArrayInquirer class inherits from
any? method performs same as
Array class when no arguments are passed.
Use inquiry method on array to fetch Array Inquirer version
For any given array we can have its Array Inquirer version by calling
inquiry method on it.
Usage of Array Inquirer in Rails code
Rails 5 makes use of Array Inquirer and provides a better way of checking for the presence of given variant.
Before Rails 5 code looked like this.
Corresponding Rails 5 version is below.