# Ini file reader/writer

**URL:** <https://www.ruby-forum.com/t/ini-file-reader-writer/156338>\
**Category:** Ruby\
**Created:** [December 24, 2008, 7:19pm UTC](https://www.ruby-forum.com/t/ini-file-reader-writer/156338 "2008-12-24T19:19:42Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![madhan\_sym](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/9de053/32.png) [@madhan\_sym](https://www.ruby-forum.com/u/madhan_sym)\
**Post date:** [December 24, 2008, 7:19pm UTC](https://www.ruby-forum.com/t/ini-file-reader-writer/156338/1 "2008-12-24T19:19:42Z")

</div>

Hi Guys,

I am new joinee to this forum and also to ruby language.After spent two  
weeks of ruby learning,I have written a module “IniParser” which  
basically read/write ini files.  
I know there are few ruby gems available but i am writing this to get  
handson exp in ruby

It would be great help if someone(expert in ruby language) test this  
code and let me know your comments.This would help me to know more about  
ruby programming.

Attached file.

---

<div class="post-metadata">

**Author:** ![madhan\_sym](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/9de053/32.png) [@madhan\_sym](https://www.ruby-forum.com/u/madhan_sym)\
**Post date:** [December 24, 2008, 10:50pm UTC](https://www.ruby-forum.com/t/ini-file-reader-writer/156338/2 "2008-12-24T22:50:38Z")

</div>

On Dec 24, 7:10 pm, Madhan N. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> ruby programming.
> 
> Attached file.
> 
> Attachments:[http://www.ruby-forum.com/attachment/3100/IniParser.rb](http://www.ruby-forum.com/attachment/3100/IniParser.rb)
> 
> –  
> Posted viahttp://www.ruby-forum.com/.

After just a quick look I have to advise you to take look at  
[INI file - Wikipedia](http://en.wikipedia.org/wiki/INI_file) for ini file specification that  
your IniParser should take in consideration. Specially comments, keys  
outside of session, empty session in front of another session…

The second thing you should reconsider is the way we should use this  
IniParser in real life.  
Is it wise to parse, again, ini file for every session key that we are  
supposed to read from that ini file? Just image a long ini file with  
multiple sessions and lot of keys (mysql.ini, win.ini).

The best way will be to make a bunch of unit tests and usage samples.

Beside the DRY you should stick to “Eat Your Own Dog Food” principle  
too.
