You're new here, aren't you?
Click Connect with Facebook to join NetworkedBlogs. NetworkedBlogs is a community of bloggers and blog lovers. Join the fun, add your blog, and connect with others who read and write about subjects you like.
Extract each word found in a block of code
This opportunity was trying to write a regular expression and we’ve probably write a better … what this function is to process a string that is word for word count every word in a block…
#!/usr/bin/ruby
#Extract each word found in a block of code
class String
def word_count
frecuencies = Hash.new(0)
downcase.scan(/\w+/) { |word| frecuencies[word] += 1 }
return frecuencies
end
end
Then you can loading under console prompt and testing funtion
>> load 'word_count.rb'
=> tru
Not enough data.
Calculated for blogs with 20+ followers.
- A Hill of Beans
flex, rails
- K.K. Exports, The Ruby People
Ruby, Precious gemstone, Gemstone
- Ananasblau
ruby, rails, webdevelopment
- Ruby Inside
ruby, rails, rubyonrails
- hasan's blog
programming, java, rails
Questions? contact: networkedblogs@ninua.com
Copyright (C) 2008, Ninua, Inc.