Is it possible to define a block in a string expression with ruby? Something like that:
tasks.collect(&:title).to_block{|arr| "#{arr.slice(0, arr.length - 1).join(", ")} and #{arr.last}" }
Instead of this:
titles = tasks.collect(&:title)
"#{titles.slice(0, titles.length - 1).join(", ")} and #{titles.last}"
If you said tasks.collect(&:title).slice(0, this.length-1), how can you make 'this' a reference to the full array passed to slice ()?
Basically, I'm just looking for a way to pass an object returned from one statement to another, without necessarily iterating it.
source
share