Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- lib/hostconnect/core_extensions/string.rb
Instance Method Summary collapse
-
#margin ⇒ Object
Useful for heredocs - removes whitespace margin.
- #requestify ⇒ Object
Instance Method Details
#margin ⇒ Object
Useful for heredocs - removes whitespace margin.
7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/hostconnect/core_extensions/string.rb', line 7 def margin lines = self.dup.split($/) min_margin = 0 lines.each do |line| if line =~ /^(\s+)/ && (min_margin == 0 || $1.size < min_margin) min_margin = $1.size end end lines.map { |line| line.sub(/^\s{#{min_margin}}/, '') }.join($/) end |
#requestify ⇒ Object
2 3 4 |
# File 'lib/hostconnect/core_extensions/string.rb', line 2 def requestify self.gsub(/Id$/, 'ID') end |