Created
August 14, 2009 13:56
-
-
Save dmichael/167849 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # There really is no need for this class. One could use java.util.Properties in JRuby, | |
| # but figuring out how to use it from JRuby was more cumbersome than just writing this class. | |
| # Parser stolen from | |
| # http://devender.wordpress.com/2006/05/01/reading-and-writing-java-property-files-with-ruby/ | |
| class JavaProperties < Hash | |
| attr_accessor :file | |
| # Takes a file and loads the properties in that file | |
| def initialize(file) | |
| @file = file | |
| IO.foreach(file) do |line| | |
| self[$1.strip] = $2.strip if line =~ /([^=]*)=(.*)\/\/(.*)/ || line =~ /([^=]*)=(.*)/ | |
| end | |
| end | |
| # A getter method for kicks | |
| def get(key) | |
| self[key] | |
| end | |
| # A setter method for kicks | |
| def set(key, value) | |
| self[key] = value | |
| end | |
| #Save the properties back to file | |
| def save | |
| file = File.new(@file,"w+") | |
| self.each {|key,value| file.puts "#{key}=#{value}\n" } | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment