2 ms·
As presented, this one is quite dangerous because it's easy to miss the variable assignment. File.read('data.txt') .split("\n") .map { |ln| some_proc
by tremon 3y ago
As presented, this one is quite dangerous because it's easy to miss the variable assignment.
File.read('data.txt')
.split("\n")
.map { |ln| some_processing(ln) }
.select { |ln| some_filter(ln) }
.and_so_on => result
I never knew this type of assignment was possible in Ruby, but I will use it if the => var can follow on the next line. A quick test (in 3.1) suggests that it only works with an explicit line continuation:
File.read('data.txt')
.split("\n") \
=> result
...which makes it less appealing. I'll have to try it for a bit to see if I prefer it over the normal `result =` assignment syntax.