Reputation: 15
I want to convert this:
courses = client.query("SELECT LCASE(name) FROM courses")
into an array, so I can easily loop through elements in some existing code, much appreciated.
Upvotes: 0
Views: 2246
Reputation: 30071
If that courses
object is a Mysql2::Result
you already can because it includes the Enumerable
module. So you can use each
, select
, first
and all the others methods from the module. Anyway, if you actually want an array object
courses = client.query("SELECT LCASE(name) FROM courses").to_a
to_a
is from Enumerable
module as well
courses = client.query("SELECT LCASE(name) AS name FROM courses")
course_names = courses.map { |course| course['name'] }
course_names.each { |course_name| puts course_name }
Upvotes: 1