# Ruby equivalent for property or config.xml?

**URL:** <https://www.ruby-forum.com/t/ruby-equivalent-for-property-or-config-xml/86578>\
**Category:** Ruby\
**Created:** [February 23, 2007, 1:12pm UTC](https://www.ruby-forum.com/t/ruby-equivalent-for-property-or-config-xml/86578 "2007-02-23T13:12:33Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![RebhanS\_Gilbert](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/7feea3/32.png) [@RebhanS\_Gilbert](https://www.ruby-forum.com/u/RebhanS_Gilbert)\
**Post date:** [February 23, 2007, 1:12pm UTC](https://www.ruby-forum.com/t/ruby-equivalent-for-property-or-config-xml/86578/1 "2007-02-23T13:12:33Z")

</div>

Hi,

i have a ruby script that should be controlled via  
configfile, similar as a propertyfile or config.xml in java.

What’s the ruby equivalent for that ?

Gilbert

---

<div class="post-metadata">

**Author:** ![RebhanS\_Gilbert](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/7feea3/32.png) [@RebhanS\_Gilbert](https://www.ruby-forum.com/u/RebhanS_Gilbert)\
**Post date:** [February 23, 2007, 1:15pm UTC](https://www.ruby-forum.com/t/ruby-equivalent-for-property-or-config-xml/86578/2 "2007-02-23T13:15:33Z")

</div>

On 23/02/07, Rebhan, Gilbert [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> 

Your best bet is probably YAML which is part of the standard library.

Farrel

---

<div class="post-metadata">

**Author:** ![RebhanS\_Gilbert](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/7feea3/32.png) [@RebhanS\_Gilbert](https://www.ruby-forum.com/u/RebhanS_Gilbert)\
**Post date:** [February 23, 2007, 2:06pm UTC](https://www.ruby-forum.com/t/ruby-equivalent-for-property-or-config-xml/86578/3 "2007-02-23T14:06:37Z")

</div>

Farrel L. wrote:

> > 
> 
> Your best bet is probably YAML which is part of the standard library.
> 
> Farrel

Or just a ruby file…

module Config  
DATABASE = {:adapter =\> ‘foo’ …}  
FROBNICATOR = :fozzbangle  
LOCATION = :coozbain  
end

---

<div class="post-metadata">

**Author:** ![RebhanS\_Gilbert](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/7feea3/32.png) [@RebhanS\_Gilbert](https://www.ruby-forum.com/u/RebhanS_Gilbert)\
**Post date:** [February 23, 2007, 2:22pm UTC](https://www.ruby-forum.com/t/ruby-equivalent-for-property-or-config-xml/86578/4 "2007-02-23T14:22:41Z")

</div>

On 2/23/07, Rebhan, Gilbert [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> i have a ruby script that should be controlled via  
> configfile, similar as a propertyfile or config.xml in java.
> 
> What’s the ruby equivalent for that ?

YAML is what you want, though parsing properties files into ruby  
hashes is straightforward.

Even in java, XML files for configuration are overkill.

---

<div class="post-metadata">

**Author:** ![RebhanS\_Gilbert](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/7feea3/32.png) [@RebhanS\_Gilbert](https://www.ruby-forum.com/u/RebhanS_Gilbert)\
**Post date:** [March 3, 2007, 10:01am UTC](https://www.ruby-forum.com/t/ruby-equivalent-for-property-or-config-xml/86578/5 "2007-03-03T10:01:37Z")

</div>

> YAML is what you want, though parsing properties files into ruby  
> hashes is straightforward.

I wondered whether some features of Apache Jakarta Commons Configuration  
format are available with YAML (or another Ruby gismo):

[http://jakarta.apache.org/commons/configuration/apidocs/org/apache/commons/configuration/PropertiesConfiguration.html](http://jakarta.apache.org/commons/configuration/apidocs/org/apache/commons/configuration/PropertiesConfiguration.html)

Two interesting features:

1. Variable expansion:

user.name = miles  
first\_file = /home/${user.name}/first  
app\_title = ${user.name}'s homepage

I think variable expansion is done on reference (“lazy”). YAML has  
aliases, but can’t concatenate strings (which is OK, because YAML is for  
object (de)serialization…).

1. Layout preservation: The ‘load’ methods saves the layout of the  
properties file, including comments, line order, indentation. The ‘save’  
method tries to preserve as much of it as possible. See:

[http://jakarta.apache.org/commons/configuration/apidocs/org/apache/commons/configuration/PropertiesConfigurationLayout.html](http://jakarta.apache.org/commons/configuration/apidocs/org/apache/commons/configuration/PropertiesConfigurationLayout.html)

Best,  
Dov.
