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.
2060 2061 2062 2063 2064 2065 2066 |
# File 'lib/cgen/cgen.rb', line 2060 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.
2079 2080 2081 |
# File 'lib/cgen/cgen.rb', line 2079 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.
2070 2071 2072 2073 2074 2075 2076 |
# File 'lib/cgen/cgen.rb', line 2070 def tabto n if self =~ /^( *)\S/ tab(n - $1.length) else self end end |