sonic-pi

https://github.com/sonic-pi-net/sonic-pi

C++

Code. Music. Live.

String#indent

Indents the lines in the receiver:

  <<EOS.indent(2)
  def some_method
    some_code
  end
  EOS
  # =>
    def some_method
      some_code
    end

The second argument, +indent_string+, specifies which indent string to
use. The default is +nil+, which tells the method to make a guess by
peeking at the first indented line, and fallback to a space if there is
none.

  "  foo".indent(2)        # => "    foo"
  "foo\n\t\tbar".indent(2) # => "\t\tfoo\n\t\t\t\tbar"
  "foo".indent(2, "\t")    # => "\t\tfoo"

While +indent_string+ is typically one space or tab, it may be any string.

The third argument, +indent_empty_lines+, is a flag that says whether
empty lines should be indented. Default is false.

  "foo\n\nbar".indent(2)            # => "  foo\n\n  bar"
  "foo\n\nbar".indent(2, nil, true) # => "  foo\n  \n  bar"

Source | Google | Stack overflow

Edit

git clone [email protected]:sonic-pi-net/sonic-pi.git

cd sonic-pi

open app/server/ruby/vendor/activesupport-7.0.6/lib/active_support/core_ext/string/indent.rb

Contribute

# Make a new branch

git checkout -b -your-name--update-docs-String-indent-for-pr


# Commit to git

git add app/server/ruby/vendor/activesupport-7.0.6/lib/active_support/core_ext/string/indent.rbgit commit -m "better docs for String#indent"


# Open pull request

gem install hub # on a mac you can `brew install hub`

hub fork

git push <your name> -your-name--update-docs-String-indent-for-pr

hub pull-request


# Celebrate!