I'm not addressing your overall point, but one thing I learned about recently that could help in debugging those Ruby one-liners is the `tap` method. You can stick it in the chain and set a breakpoint.
def build_hash_or_whatever
hash = Hash.new
hash[:foo] = some_generating_method
hash[:bar] = "some value" if whatever?
# More hash construction nonsense
hash
end
With tap it is: def build_hash_or_whatever
Hash.new.tap do |hash|
hash[:foo] = some_generating_method
hash[:bar] = "some value" if whatever?
# More hash construction nonsense
end
end
I think the tap-form is significantly worse and I don't understand the aversion to a single line that clearly shows what you are returning.