When executing the following code,
game.rb:3:undefined method `table' for CSV:Class(NoMethodError)
An error similar to this appears.
How can I deal with the error?
ruby file (game.rb)
require'csv'
csv = CSV.table ('data.csv')
time = csv[:time]# To specify a header
puts time.class#=>array
puts time#=>10:00
# 20:00
# 03:00
one = csv[1]# To specify a line
puts one.class#=>CSV::Row
put one#=>20:10, GOODNIGHT, miki
put one [:time]#=>20:10
csv file (data.csv)
time, text, user
10:00, Hello, tarou
20:10, GOODNIGHT, miki
03:00, SINTYOKUDAME, se
The reason is that the Ruby version is out of date as discussed in the comments.
The code in question works with Ruby 1.9 or higher, but since the 1.9 series has also finished maintenance, I think it would be better to update it to at least 2.0 or higher.(Ideal for using the current latest version of 2.2.3)
As for the version upgrade method, recently the mainstream is to use rbenv (or RVM) to switch to any version.
I will link the official page of rbenv for your reference.
https://github.com/sstephenson/rbenv
If you search the Internet, you will find a lot of information in Japanese, so please refer to them and proceed as follows.
369 Update Flask User Information
362 To Limit Column Values to Strings in a String List Using sqlalchemy
345 Who developed the "avformat-59.dll" that comes with FFmpeg?
366 Is there any other way to save the Python database?
355 Unity Virtual Stick Does Not Return to Center When You Release Your Finger
© 2023 OneMinuteCode. All rights reserved.