1. 13
    1. 8

      I, personally, have been using one-line methods a lot in the past year. They feel MUCH more expressive when you become accustomed to them.

      Shorthand methods are more-readable than 3-line boilerplate methods or the hacky one-liner style def foo; bar end . It affects the way I write and code - I am more free to make simple methods. I also feel comfortable organizing shorthand methods in dense blocks (no whitespace between them) where they represent logical groupings:

      def isbn = lookup(“isbn”)
      def barcode = lookup(“barcode”)
      
      def title = lookup(“title”) || “unknown”
      def author = lookup(“author”)
      

      The above code coveys more information to me because of its shape. For the skeptical: rewrite that same code in the other styles. I have written them the other way, and have found it aesthetically unsatisfying to the point of writing code in a style that would avoid it.

      There’s also an idiom I’ve picked up: the one-line super method:

      class Document
        def title(lang: “en”)
          return @title.to_s if lang == “en”
          @title.translate(lang)
        end 
      end
      
      class SpanishDocument < Document
        def title = super(lang: “es”)
      end
      

      The example is a little convoluted, but what works for me about this is the providing arguments to a super method when there’s inheritance. I conceptualize it as acting like a mask over the api that can provide a layer of information. Decorating is another perspective. However you think of it, it clicks for me in the shorthand syntax.

      1. 4

        Same, endless methods have almost entirely taken over where I used to use delegators