I have an array of objects with a boolean attribute:
[#<Animal id: 1, type: "narwhal", magical: false>, #<Animal id: 2, type: "unicorn", magical: true>]
How do I create a new array with only the objects where the boolean :magical? is true?
Are you looking for Enumerable#select?
a = [#<Animal id: 1, type: "narwhal", magical: false>, #<Animal id: 2, type: "unicorn", magical: true>]
b = a.select(&:magical?)
b
=> [#<Animal id: 2, type: "unicorn", magical: true>]
true/false not just a trueish or falseish value.magical? to a proc, but we haven't been told about a method by that name. Am I missing something? I'll check back in the morning.