News for hackers. Stuff that matters.
Re:Write code that is easy to delete, not easy to extend by GavinMcG on Sunday February 14, 2016 @11:09AM (#11098755)
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.

http://ruby-doc.org/core-2.2.3/Object.html#method-i-tap

Re:Write code that is easy to delete, not easy to extend by tvon on Sunday February 14, 2016 @12:35PM (#11099091)
Further off-topic, but I almost exclusively see tap used as some kind of clever way around a return line, e.g. instead of:

    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.
Re:Write code that is easy to delete, not easy to extend by plaguuuuuu on Sunday February 14, 2016 @05:47PM (#11100369)
Changing code to enable debugging is barbaric. Tooling should be able do that. Or maybe I'm spoiled, lol.