SitePoint Sponsor |
|
User Tag List
Results 1 to 4 of 4
Hybrid View
-
Nov 9, 2008, 18:02 #1
- Join Date
- Oct 2008
- Posts
- 5
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
why is there an error in my counter method?
Code:class BrowserCount def initialize(file = "browsers.txt") @file_lines = Array.new @file = file end def counter read_file @hash = Hash.new @files_lines.uniq.each do |line| count = 0 @file_lines.each do |x| if x == line count +=1 end end @hash[line]=count end @hash end private def read_file if @file_lines.empty? @open_file = File.open(@file) @file_lines = @open_file.readlines() end end end B = BrowserCount.new B.counter
-
Nov 9, 2008, 18:37 #2
You set a @file_lines variable; on 10 you're looking for @files_lines.
.
Zach Holman
good-tutorials — blog — twitter — last.fm
-
Nov 9, 2008, 19:18 #3
- Join Date
- Oct 2008
- Posts
- 5
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
but I call read_file
-
Nov 10, 2008, 01:18 #4
@files_lines.uniq.each do |line|
vs.
@file_lines = @open_file.readlines()
file_lines != files_lines.
Zach Holman
good-tutorials — blog — twitter — last.fm
Bookmarks