Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Ruby wrapper around Java Properties
# More rubyish/convenient interface to Java Properties(e.g. Loading connection config from properties file)
class JavaProperties
def initialize(name)
input_stream =
Java::Java.lang.Thread.currentThread.contextClassLoader.getResourceAsStream(name)
if input_stream
@properties = Java::java.util.Properties.new
@properties.load(input_stream)
input_stream.close
else
raise "#{name} not found in classpath"
end
end
def [](name)
@properties.getProperty(name)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment