Ruby " yield row if block_given?"
ruby
Solution
This `yield row if block_given?` means that block which could be passed into the `#queryNewsTable` method(!), is evaluated with yield operator, in other words, if you pass the block into function `#queryNewsTable`:
queryNewsTable do
#some code
end
You will get the call to the code, for each of rows in the `result` variable.
NOTE: That for your case it will be better to optimize the code (if not dbtrigger is used):
# Get our data back
def queryNewsTable
@conn.exec( "SELECT * FROM newslib" ) do |result|
result.each do |row|
yield row
end
end if block_given?
end
Problem
``` # Get our data back def queryNewsTable @conn.exec( "SELECT * FROM newslib" ) do |result| result.each do |row| yield row if block_given? end end end ``` For this piece of code. I don't quite understand `yield row if block_given?` can anybody point to any good article teaching about this or you can briefly explain it to me a little bit thanks so much