Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- lib/cgen/cgen.rb
Overview
class Array def join_nonempty str map { |x|. x.to_s }.reject { |s| s == "" }.join(str) end end
Instance Method Summary collapse
-
#tab(n) ⇒ Object
Tabs left or right by n chars, using spaces.
-
#taballto(n) ⇒ Object
Aligns each line to have n spaces before the first non-space.
-
#tabto(n) ⇒ Object
The first non-empty line is adjusted to have n spaces before the first nonspace.
Instance Method Details
#tab(n) ⇒ Object
Tabs left or right by n chars, using spaces.
2052 2053 2054 2055 2056 2057 2058 |
# File 'lib/cgen/cgen.rb', line 2052 def tab n if n >= 0 gsub(/^/, ' ' * n) else gsub(/^ {0,#{-n}}/, "") end end |
#taballto(n) ⇒ Object
Aligns each line to have n spaces before the first non-space.
2071 2072 2073 |
# File 'lib/cgen/cgen.rb', line 2071 def taballto n gsub(/^ */, ' ' * n) end |
#tabto(n) ⇒ Object
The first non-empty line is adjusted to have n spaces before the first nonspace. Additional lines are changed to preserve relative tabbing.
2062 2063 2064 2065 2066 2067 2068 |
# File 'lib/cgen/cgen.rb', line 2062 def tabto n if self =~ /^( *)\S/ tab(n - $1.length) else self end end |