Ruby’s backslash line continuation

    It’s such a simple thing, but I love that Ruby treats the backslash character as a line continuation, similar to a shell.

    I often use it to omit parens and group keyword arguments on new line.

    app/models/page/resource.rb
    def self.from(sitepress_resource)
      Resource.new \
        request_path: sitepress_resource.request_path,
        body: sitepress_resource.body,
        title: sitepress_resource.data.title,
        description: sitepress_resource.data.description,
        image: sitepress_resource.data.image,
        # ...

    Back to snippets