remove prefixed '-' signs, then allow any letter, number, underscore '_' or dash '-'
# File lib/sugar-high/string.rb, line 26 def alpha_numeric self.gsub(/^\-+/, '').gsub(/[^0-9a-zA-Z_\-]+/, '') end
# File lib/sugar-high/arguments.rb, line 33 def args (self =~ /\w+\s+\w+/) ? self.split : self end
# File lib/sugar-high/file.rb, line 40 def as_filename self.underscore end
# File lib/sugar-high/string.rb, line 18 def concats *args args.inject(self) do |res, arg| res << arg.to_s res end end
# File lib/sugar-high/file.rb, line 53 def dir return ::Dir.new(self) if ::File.directory?(self) raise "No file found at #{self}" end
# File lib/sugar-high/file.rb, line 48 def file return ::File.new(self) if ::File.file?(self) raise "No file found at #{self}" end
# File lib/sugar-high/string.rb, line 30 def insert_before_last str, marker = 'end' res = [] found = false marker = case marker when Symbol, String marker.to_s when Hash marker[:marker].to_s else raise ArgumentException, "last argument is the marker and must be a String, Symbol or even Hash with a :marker option pointing to the marker (String or Symbol)" end marker = Regexp.escape(marker.to_s.reverse) nl = Regexp.escape("\n") self.reverse.each_line do |x| x.gsub! /#{nl}/, '' if !found && x =~ /#{marker}/ replace = "#{str}\n" << x.reverse res << replace found = true else res << x.reverse end end res = res.reverse.join("\n") end
# File lib/sugar-high/file.rb, line 58 def new_file begin file rescue File.open(self, 'w') end end
# File lib/sugar-high/path.rb, line 2 def path self.extend PathString end
Generated with the Darkfish Rdoc Generator 2.