Reading from an INI

By log2 on Nov 10, 2005

This reads information from an ini file



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!

EDITED

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

Sign in to comment.
Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.