Forum: Ruby Re: Using Ruby to read .properties file

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Lock Stephen (Guest)
on 2006-06-06 17:59
(Received via mailing list)
None that I know of without writing code - but there isn't much to it.
Try this:

  def load_properties(properties_filename)
    properties = {}
    File.open(properties_filename, 'r') do |properties_file|
      properties_file.read.each_line do |line|
        line.strip!
        if (line[0] != ?# and line[0] != ?=)
          i = line.index('=')
          if (i)
            properties[line[0..i - 1].strip] = line[i + 1..-1].strip
          else
            properties[line] = ''
          end
        end
      end
    end
    properties
  end

Unashamedly taken from http://www.bigbold.com/snippets/posts/show/1311
unknown (Guest)
on 2006-06-06 18:38
(Received via mailing list)
Thanks a lot for the code

sanchit




"Lock Stephen" <removed_email_address@domain.invalid>
06/06/2006 07:29 PM
Please respond to
removed_email_address@domain.invalid


To
removed_email_address@domain.invalid (ruby-talk ML)
cc

Subject
Re: Using Ruby to read .properties file






None that I know of without writing code - but there isn't much to it.
Try this:

  def load_properties(properties_filename)
    properties = {}
    File.open(properties_filename, 'r') do |properties_file|
      properties_file.read.each_line do |line|
        line.strip!
        if (line[0] != ?# and line[0] != ?=)
          i = line.index('=')
          if (i)
            properties[line[0..i - 1].strip] = line[i + 1..-1].strip
          else
            properties[line] = ''
          end
        end
      end
    end
    properties
  end

Unashamedly taken from http://www.bigbold.com/snippets/posts/show/1311
This topic is locked and can not be replied to.