Trying to open a file in Ruby - Getting TypeError: can't convert String into Integer

Posted by steve_gallagher on Stack Overflow See other posts from Stack Overflow or by steve_gallagher
Published on 2012-06-19T21:06:50Z Indexed on 2012/06/19 21:16 UTC
Read the original article Hit count: 161

Filed under:
|
|

Not sure whats going on here, or what could be the integer in this case. Here's the code:

def build_array_from_file(filename)
    contents = []
    File.read(File.expand_path('lib/project_euler/' + filename), 'r') do |file|
      while line = file.get
        contents << line
      end
    end
    contents
  end

filename is a string and I've checked to make sure the path comes up valid.

Any thoughts? Thanks.

© Stack Overflow or respective owner

Related posts about ruby

Related posts about file