Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

About this user

Danny Lagrouw http://blog.dannynet.net

« Newer Snippets
Older Snippets »
Showing 1-1 of 1 total  RSS 

Load properties from properties file into Hash

Loads properties from a file with lines formatted as 'key=value' into a Hash. Comments (lines starting with #) are skipped, as are lines starting with =. Empty property values (lines ending with =) and property values containing = are included in the Hash.

   1  
   2    def load_properties(properties_filename)
   3      properties = {}
   4      File.open(properties_filename, 'r') do |properties_file|
   5        properties_file.read.each_line do |line|
   6          line.strip!
   7          if (line[0] != ?# and line[0] != ?=)
   8            i = line.index('=')
   9            if (i)
  10              properties[line[0..i - 1].strip] = line[i + 1..-1].strip
  11            else
  12              properties[line] = ''
  13            end
  14          end
  15        end      
  16      end
  17      properties
  18    end
« Newer Snippets
Older Snippets »
Showing 1-1 of 1 total  RSS