Module: Tins::To
- Included in:
- Object
- Defined in:
- lib/tins/to.rb
Overview
Provides a simple way to remove common leading whitespace from multi-line strings, mostly for to(<<-EOT), if require “tins/xt/to”. Today you would probably use <<~EOT in this case.
Example usage:
doc = to(<<-EOT)
hello
world
end
EOT
# => "hello\n world\nend"
Instance Method Summary collapse
-
#to(string) ⇒ String
Remove common leading whitespace from multi-line strings.
Instance Method Details
#to(string) ⇒ String
Remove common leading whitespace from multi-line strings
18 19 20 21 |
# File 'lib/tins/to.rb', line 18 def to(string) shift_width = (string[/\A\s*/]).size string.gsub(/^[^\S\n]{0,#{shift_width}}/, '') end |