Search code examples
rubyhashsinatrathinwebrick

Sinatra: Undefined method bytesize for Hash


I'm creating a Sinatra app that takes an uploaded CSV file and puts its contents in a hash. When I reference this hash in my app.rb like so:

hash = extract_values(path_to_filename)

I keep getting this error message:

undefined method `bytesize' for Hash:0x007fc5e28f2b90 #object_id

file: utils.rb location: bytesize line: 335

I read somewhere that this is a Webrick issue. I switched to Thin, the error's the same.

My hash / CSV file is of very small size, so it can't be the issue.

I'm using ruby 1.9.3p374.

Thanks!


Solution

  • This looks like a duplicate of Undefined method `bytesize' for #<Hash>

    Sinatra is expecting a string be returned (i.e. last line) of the route method; you can't just return a straight hash.