Created
April 30, 2011 14:15
-
-
Save nerdyworm/949700 to your computer and use it in GitHub Desktop.
Silly list based noun finder
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class String | |
@@nouns = [] | |
def is_noun? | |
String.nouns.include? self.downcase | |
end | |
def find_nouns | |
self.split(/\s/).collect { |w| w if w.is_noun? }.compact | |
end | |
def self.nouns | |
if @@nouns.empty? | |
File.open('nouns_list.txt','r') do |f| | |
f.each_line do |line| | |
@@nouns.push line.strip.downcase | |
end | |
end | |
end | |
@@nouns | |
end | |
end | |
input = IO.read('input.txt') | |
puts input.to_s.find_nouns |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment