lib/kumogata/ext/string_ext.rb in kumogata-0.2.6 vs lib/kumogata/ext/string_ext.rb in kumogata-0.2.7
- old
+ new
@@ -28,11 +28,16 @@
def encode64
Base64.encode64(self).delete("\n")
end
def undent
- min_space_num = self.split("\n").delete_if{|s| s=~ /^\s*$/ }.map{|s| s[/^\s+/].length }.min
- gsub(/^[ \t]{,#{min_space_num}}/, '')
+ min_space_num = self.split("\n").delete_if {|s| s =~ /^\s*$/ }.map {|s| (s[/^\s+/] || '').length }.min
+
+ if min_space_num and min_space_num > 0
+ gsub(/^[ \t]{,#{min_space_num}}/, '')
+ else
+ self
+ end
end
def fn_join(options = {})
options = {
:undent => true,