Project

General

Profile

Feature #13047

Use String literal instead of `String#+` for multiline pretty-printing of multiline strings

Added by mtsmfm (Fumiaki Matsushima) over 2 years ago. Updated over 2 years ago.

Status:
Assigned
Priority:
Normal
Target version:
-
[ruby-core:78708]

Description

Multiline pretty-printing of multiline strings is introduced. (https://bugs.ruby-lang.org/issues/12664)

> pp "bundler.rb"=> "module Bundler\n  BundlerError = Class.new(Exception)\n  def self.setup\n  end\nend\n"
{"bundler.rb"=>
  "module Bundler\n" +
  "  BundlerError = Class.new(Exception)\n" +
  "  def self.setup\n" +
  "  end\n" +
  "end\n"}

It is awesome but we can use String literal instead of String#+:

> pp "bundler.rb"=> "module Bundler\n  BundlerError = Class.new(Exception)\n  def self.setup\n  end\nend\n"
{"bundler.rb"=>
  "module Bundler\n" \
  "  BundlerError = Class.new(Exception)\n" \
  "  def self.setup\n" \
  "  end\n" \
  "end\n"}

It seems that pp want to output evaluable snippet but we can override String#+ so it may not work well.

Non-broken String will be:

> pp "bundler.rb"=> "module Bundler\nend\n"
{"bundler.rb"=> "module Bundler\n" "end\n"}

How do you think?


I tried to write patch but I can't find a way to append "\" to broken line only by current PP's API.

History

Updated by shyouhei (Shyouhei Urabe) over 2 years ago

Fumiaki Matsushima wrote:

Non-broken String will be:

> pp "bundler.rb"=> "module Bundler\nend\n"
{"bundler.rb"=> "module Bundler\n" "end\n"}

How do you think?

There are debates on this "strng" "concatenation" notation. https://bugs.ruby-lang.org/issues/6265
It is questionable if we still prefer this way.

I tried to write patch but I can't find a way to append "\" to broken line only by current PP's API.

No, I heard there is currently no way to change formats between one / multi -lined outputs. You have to extend PP itself.

Updated by shyouhei (Shyouhei Urabe) over 2 years ago

  • Assignee set to akr (Akira Tanaka)
  • Status changed from Open to Assigned

Also available in: Atom PDF