by _zagj · 1y ago · 0 comments
> [
> "beige chinos",
> "blue jorts",
> "rainbow jorts",
> ].filter { it =~ /jorts/ }
> # => ["blue jorts", "rainbow jorts"]
This reminds me of Perl's $_ (which in Ruby is last line read from STDIN).
ary.grep /(j|sh)orts/
already exists, and therefore sells the standard library short. try this: terms = %w(foo? bar q**x)
Regexp.new "\\b(#{terms.map { Regexp.escape it }.join ?|})\\b"
#=> /\b(foo\?|bar|q\*\*x)\b/
and observe that it's at the margins of instant comprehension where syntax shorthands like "it" add value.