voipfc / googlemail.com wrote:
>
> What is ruby's equivalent of PHPs explode?
>
> A routine which can breakdown a string and return the results in an
> array or a routine that can parse an .ini file and return the key
> value pairs in an array[key]=value.
Actually, that is two questions. As to the first (explode a string on word
boundaries), you've been given an answer:
array = string.split("\s") # many variations
As to the second, read an .ini file and break it down by line and by
name/value pairs (not tested):
data = File.read("filename.ini")
my_hash = {}
data.each do |line|
key,value = line.split("=")
my_hash[key] = value
end
The second won't work properly if there are any equals signs in the value
field. The solution for this is only a bit more complex.
--
Paul Lutus
http://www.arachnoid.com