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

···

-----Original Message-----
From: Sanchit.Misra@trilogy.com [mailto:Sanchit.Misra@trilogy.com]
Sent: 06 June 2006 14:52
To: ruby-talk ML
Subject: Using Ruby to read .properties file

Hi

I am working on a project in which I need to read and write the
.properties files. Is there a way to do this in Ruby ... other than
writing code from scratch.
Thanks in advance.

regards
Sanchit

************************************************************************
DISCLAIMER
The information contained in this e-mail is confidential and is intended
for the recipient only.
If you have received it in error, please notify us immediately by reply
e-mail and then delete it from your system. Please do not copy it or
use it for any other purposes, or disclose the content of the e-mail
to any other person or store or copy the information in any medium.
The views contained in this e-mail are those of the author and not
necessarily those of Admenta UK Group.
************************************************************************

Thanks a lot for the code

sanchit

"Lock Stephen" <Stephen.Lock@Lloydspharmacy.co.uk>
06/06/2006 07:29 PM
Please respond to
ruby-talk@ruby-lang.org

To
ruby-talk@ruby-lang.org (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

···

-----Original Message-----
From: Sanchit.Misra@trilogy.com [mailto:Sanchit.Misra@trilogy.com]
Sent: 06 June 2006 14:52
To: ruby-talk ML
Subject: Using Ruby to read .properties file

Hi

I am working on a project in which I need to read and write the
.properties files. Is there a way to do this in Ruby ... other than
writing code from scratch.
Thanks in advance.

regards
Sanchit

************************************************************************
DISCLAIMER
The information contained in this e-mail is confidential and is intended
for the recipient only.
If you have received it in error, please notify us immediately by reply
e-mail and then delete it from your system. Please do not copy it or
use it for any other purposes, or disclose the content of the e-mail
to any other person or store or copy the information in any medium.
The views contained in this e-mail are those of the author and not
necessarily those of Admenta UK Group.
************************************************************************