aboutsummaryrefslogtreecommitdiffstats
path: root/guides/source/active_support_core_extensions.textile
diff options
context:
space:
mode:
authorXavier Noria <fxn@hashref.com>2012-08-07 16:55:28 +0200
committerXavier Noria <fxn@hashref.com>2012-08-07 16:57:28 +0200
commit2f58795e783150f2e1b1f6c64e305703f0061129 (patch)
treecaa757a14597b9d6a65104bc5d85c009f9160820 /guides/source/active_support_core_extensions.textile
parent9cd1f697f1b4dded0f18e13c7ae12c7bd2dab1c0 (diff)
downloadrails-2f58795e783150f2e1b1f6c64e305703f0061129.tar.gz
rails-2f58795e783150f2e1b1f6c64e305703f0061129.tar.bz2
rails-2f58795e783150f2e1b1f6c64e305703f0061129.zip
defines String#indent [closes #7263] [Xavier Noria & Ace Suares]
Diffstat (limited to 'guides/source/active_support_core_extensions.textile')
-rw-r--r--guides/source/active_support_core_extensions.textile35
1 files changed, 35 insertions, 0 deletions
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:
+
+<ruby>
+<<EOS.indent(2)
+def some_method
+ some_code
+end
+EOS
+# =>
+ def some_method
+ some_code
+ end
+</ruby>
+
+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.
+
+<ruby>
+" foo".indent(2) # => " foo"
+"foo\n\t\tbar".indent(2) # => "\t\tfoo\n\t\t\t\tbar"
+"foo".indent(2, "\t") # => "\t\tfoo"
+</ruby>
+
+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.
+
+<ruby>
+"foo\n\nbar".indent(2) # => " foo\n\n bar"
+"foo\n\nbar".indent(2, nil, true) # => " foo\n \n bar"
+</ruby>
+
+The +indent!+ method performs indentation in-place.
+
h4. Access
h5. +at(position)+