AhmetMelihBaşbuğ AhmetMelihBaşbuğ - 4 months ago 18
Ruby Question

In Ruby, each_hash function syntax error, unexpected tIDENTIFIER, expecting keyword

I try to connect my database with ruby in that example and I want to put output name, surname from members table. However i couldn't show output as

name surname
. It has error. I am new in ruby. How can use
in that example? Output:

name surname
name1 surname1

my code:

con = Mysql.new('localhost', 'root', 'root', 'ruby')
rs = con.query('select * from members')
rs.each_hash { |name, surname| puts name['name'], puts surname['surname']}


$> ruby membershow.rb

membershow.rb:7: syntax error, unexpected tIDENTIFIER, expecting
keyword_do or '{' or '(' ...puts name['name'], puts



You can not use , to separate lines or end line. It should be ;. use this:

rs.each_hash { |name, surname| puts name['name']; puts surname['surname']}