4 ms·
Ruby version is a pretty clear one-liner: validated_items = items.select { |item| is_validated?(item) } Though I'd expect a check for validation to be an
by brobinson 10y ago
Ruby version is a pretty clear one-liner:
validated_items = items.select { |item| is_validated?(item) }
Though I'd expect a check for validation to be an instance method, so it'd probably look like:
validated_items = items.select(&:validated?)
- Singletoned 10y agoI don't find either of the Ruby versions clear at all. Both contain unnecessary syntax. Ruby seems to be going down the same path as Perl in trying to make all possible combinations of characters valid programs.
- lparry 10y agoEven if it's not an instance method you can write the first as validated_items = items.select(&method(:is_validated?)) (Typed on my phone but I'm pretty sure that's the right syntax)
- brobinson 10y agoIt is! I'd forgotten about Kernel.method. Thanks!