Rails 5 - Array Inquirer
Rails 5 has a new wrapper class for Array called ArrayInquirer
the same way StringInquirer
does, but with arrays.
irb> colors = [:blue, 'green'].inquiry
=> [:blue, "green"]
irb> colors.class
=> ActiveSupport::ArrayInquirer
This will create nice question like methods such as:
irb> colors = [:blue, 'green'].inquiry
=> [:blue, "green"]
irb> colors.blue?
=> true
irb> colors.green?
=> true
irb> colors.red?
=> false
It also creates the method any?
for you:
irb> colors = [:blue, 'green'].inquiry
=> [:blue, "green"]
irb> colors.any?('blue', :yellow)
=> true
irb> colors.any?('red', :yellow)
=> false
By the way we use StringInquirer
already:
irb> Rails.env
=> "development"
irb> Rails.env.class
=> ActiveSupport::StringInquirer
irb> Rails.env.development?
=> true