Top

Reading from an INI


Ruby / Rails Code

Please Register to submit score.
Bookmark and Share
Average Score  0.0 (of 0 scores)
Date Added  Nov 10, 2005
Last Updated  Nov 10, 2005
Tags  inis 

Description

This reads information from an ini file
<BR>
Now to get this to work, make an ini file called hello.ini in a folder called hello from your main ruby directory, place this code into the file:
hello1=Hello
hello2=Hi
hello3=Hey
hello4=Heya
hello5=Shut Up!<Br>

EDITED

Grab the Code

module INI
  def self.read(filename, variable)
    File.open(filename).each{ |row|
    if row =~ Regexp.new("^" + variable + "=.*$")
      return row.scan(Regexp.new("^" + variable + "=(.*)$"))[0]
    end
    }
  end
end
 
for i in 0..5
puts INI.read("hello/Hello.ini","hello" + i.to_s)
end

Comments

  (0)  RSS

Commenting Options

Register or Login to Hawkee.com or use your Facebook or Twitter account by clicking the corresponding button below.

  

Bottom