The Artima Developer Community
Sponsored Link

Ruby Buzz Forum
Extracting a parameter

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Adam Green

Posts: 102
Nickname: darwinian
Registered: Dec, 2005

Adam Green is the author of Ruby.Darwinianweb.com
Extracting a parameter Posted: Dec 28, 2005 8:18 AM
Reply to this message Reply

This post originated from an RSS feed registered with Ruby Buzz by Adam Green.
Original Post: Extracting a parameter
Feed Title: ruby.darwinianweb.com
Feed URL: http://www.nemesis-one.com/rss.xml
Feed Description: Adam Green's Ruby development site
Latest Ruby Buzz Posts
Latest Ruby Buzz Posts by Adam Green
Latest Posts From ruby.darwinianweb.com

Advertisement
The worst part about blogging while learning a new language is that you have to publish code before you really know what you are doing. This simple program to extract the value of a parameter from a YML file is a perfect example. It works fine, but I'm sure there is a more efficient and certainly more Ruby-like way of doing it. I manage to rationalize it to myself by saying that I can use the example of rewriting this to take advantage of Ruby in the tutorial.

getparam.rb

 #! /usr/bin/ruby



def getparam(paramfile,key)
currentkey = ""
value = ""



file = File.open(paramfile)
while line = file.gets and currentkey != key
line.chomp!
if line.match(":")
currentkey,value = line.split(":")
currentkey.strip!
value.strip!
end



end
file.close



if currentkey == key
return value
else
return nil
end



end

Read: Extracting a parameter

Topic: Happy Empowered Peoplei Previous Topic   Next Topic Topic: Am I a Rails Sneezer?

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use