The check in the controller evaluates properly for
o = Object.new
['a', 'b', 'c'].any? do |i|
@var = true if args.include?(i)
if @var == true
Here's a cleaned up version of your code that's actually more Ruby-like in nature:
class MyModel attr_accessor :example VALID_VALUES = %w[ a b c ] def demo_method(value) @example = true if VALID_VALUES.include?(value) end end model = MyModel.new model.demo_method('x') model.example # => nil model.demo_method('a') model.example # => true
The problem you had in your original code is you're setting the value inside an
any? block which also does a test for inclusion. This nesting isn't required.
You also don't need to test
x == true since
x will suffice.