Always remember that while python has sane syntax (compared to
perl and php), its inner logic does not work in a 1:1
translation into ruby code.
So you must adapt it to fit the ruby model. But usually this is
trivial and straight forward.
The first thing you should do is use the same method name but
adapt it to ruby.
Something like:
def getwordcounts(url):
Would then become:
def getwordcounts(url)
end
Next thing is to understand your data structures.
I do not know python really but something like this here:
wc[word]+=1
Seems to update the dictionary, at the keyword word position,
by + 1.
With hash.default = you can specify a default value for
your keys in a hash, in ruby.
Whenever you see a loop from python, like "for x in y", the
ruby way is usually to use .each instead on an enumerator.
array.each do |line|
# do something here
end
Or shorter, rather than do/end, to use the {} block syntax.
"I'm pretty vague about "#HERE!" parts."
I don't know what the #HERE! means either. But it is clearly
a comment. Perhaps the one who wrote so wanted to jump from
#HERE! to #HERE! ?
""wc" will be an array containing the words picked up...?"
I believe wc typically is short for "word count".
And with wc[word]+=1 you count the word, kind of. 
For ruby, I tend to use something like this to count the words
in a string:
class String
···
#
#
# === word_count
# Counts word frequencies. Returns a hash.
# Usage examples:
# x = %{ Dogs cat? cat? cat dog dog dog cat dog eagle dog
dogs}.word_count
# => { "cat"=>2, "dogs"=>2, "eagle"=>1, "dog"=>5, "cat?"=>2 }
#
#
def word_count
hash = Hash.new(0)
downcase.scan(/\w+\??/) { |word| hash[word] += 1 }
return hash
end
end
(Of course you can also just use a method instead of extending class
String,
and pass the string to that method as argument.)
"there are "word" and "words" in the code but "word" does not
appear defined although it's used locally"
But it looks as if word is defined:
for word in words:
See? The word variable appears there. In ruby, this would become
something
like this here:
array.each { |word| }
--
Posted via http://www.ruby-forum.com/.