From 2f58795e783150f2e1b1f6c64e305703f0061129 Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Tue, 7 Aug 2012 16:55:28 +0200 Subject: defines String#indent [closes #7263] [Xavier Noria & Ace Suares] --- .../source/active_support_core_extensions.textile | 35 ++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'guides/source') diff --git a/guides/source/active_support_core_extensions.textile b/guides/source/active_support_core_extensions.textile index 66de6fd310..109228f8c7 100644 --- a/guides/source/active_support_core_extensions.textile +++ b/guides/source/active_support_core_extensions.textile @@ -1325,6 +1325,41 @@ that amount of leading whitespace. NOTE: Defined in +active_support/core_ext/string/strip.rb+. +h4. +indent+ + +Indents the lines in the receiver: + + +< + 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 an educated guess 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 tipically 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" + + +The +indent!+ method performs indentation in-place. + h4. Access h5. +at(position)+ -- cgit v1.2.3