M
Mmcolli00 Mom
I keep getting a no method error when trying to find out if a count is
an odd number. I had tested the code with actual numbers and it works
fine. It seems like it is not liking how I am trying to use the method
'odd?' The count's class is of FixNum. I have tried converting to
interger but got same result. Here is the code that I am using. Do you
know if I need a gem or what I have not done here? Thanks. MC
searchText.rb:38: undefined method `odd?' for 8:Fixnum (NoMethodError)
from searchText.rb:30:in `each'
from searchText.rb:30
*****************************************
count1 = Hash.new(0)
File.open("NTemp.txt") do |src|
src.each_line do |line|
word1 = line.chomp.split(",")
count1[word1] += 1
#~ count2[word2] += 1
end
end
words = (count1.keys).uniq
words.each do |word|
#~ if count[word] == 1
#~ if count[word] == 2
if count[word].odd? == true
puts "Value does not contain a match: #{word}"
end
end
an odd number. I had tested the code with actual numbers and it works
fine. It seems like it is not liking how I am trying to use the method
'odd?' The count's class is of FixNum. I have tried converting to
interger but got same result. Here is the code that I am using. Do you
know if I need a gem or what I have not done here? Thanks. MC
searchText.rb:38: undefined method `odd?' for 8:Fixnum (NoMethodError)
from searchText.rb:30:in `each'
from searchText.rb:30
*****************************************
count1 = Hash.new(0)
File.open("NTemp.txt") do |src|
src.each_line do |line|
word1 = line.chomp.split(",")
count1[word1] += 1
#~ count2[word2] += 1
end
end
words = (count1.keys).uniq
words.each do |word|
#~ if count[word] == 1
#~ if count[word] == 2
if count[word].odd? == true
puts "Value does not contain a match: #{word}"
end
end