J
Johnathan Smith
hello
iv written a class which prints a a number of hashes of refrences
however it all prints on one line. What i was wondering was it is
possible to print each reference on a different line.
Any help would be much appreciated
my code is below
thanks
$linecount = 0
database = {}
opts.each do |opt, arg|
case opt
when '--style'
require arg
when '--database'
File.open(arg) { | handle |
last_tag = nil
handle.each { | line |
m = line.match(/^(\w+):\s*([\w+,\s]+)$/i)
if m # if m is a match (i.e., not nil)
if m[1] == 'Tag' # adds a key to the hash
last_tag = m[2].chomp
database[last_tag] = {} # makes a subhash as the value
else
database[last_tag][m[1]] = m[2].chomp
end
end
}
}
end
end
print "Number of References: ", database.length, "\n" # prints number
of references
print "Hash Contents: ", database.inspect, "\n" # prints hash contents
iv written a class which prints a a number of hashes of refrences
however it all prints on one line. What i was wondering was it is
possible to print each reference on a different line.
Any help would be much appreciated
my code is below
thanks
$linecount = 0
database = {}
opts.each do |opt, arg|
case opt
when '--style'
require arg
when '--database'
File.open(arg) { | handle |
last_tag = nil
handle.each { | line |
m = line.match(/^(\w+):\s*([\w+,\s]+)$/i)
if m # if m is a match (i.e., not nil)
if m[1] == 'Tag' # adds a key to the hash
last_tag = m[2].chomp
database[last_tag] = {} # makes a subhash as the value
else
database[last_tag][m[1]] = m[2].chomp
end
end
}
}
end
end
print "Number of References: ", database.length, "\n" # prints number
of references
print "Hash Contents: ", database.inspect, "\n" # prints hash contents