R
redrhodes
I've started on my first ruby project and came accross the following
code from:
http://habtm.com/articles/2005/11/13/your-site-doesnt-look-too-good-in-x-browser
Since I've managed to understand most of what's going on here, but I
still can't find a reference on how and why to use "#". From
following the code it looks like an escape character for a variable to
be populated when enclosed within quotes. Does anyone have enough
understanding on the syntax to help a ruby nubie?
class Hash
def to_sql
sql = keys.sort {|a,b| a.to_s<=>b.to_s}.inject([[]]) do |arr, key|
arr[0] << "#{key} = ?"
arr << self[key]
end
[sql[0].join(' AND ')] + sql[1..-1]
end
end
Thanks,
Richard
code from:
http://habtm.com/articles/2005/11/13/your-site-doesnt-look-too-good-in-x-browser
Since I've managed to understand most of what's going on here, but I
still can't find a reference on how and why to use "#". From
following the code it looks like an escape character for a variable to
be populated when enclosed within quotes. Does anyone have enough
understanding on the syntax to help a ruby nubie?
class Hash
def to_sql
sql = keys.sort {|a,b| a.to_s<=>b.to_s}.inject([[]]) do |arr, key|
arr[0] << "#{key} = ?"
arr << self[key]
end
[sql[0].join(' AND ')] + sql[1..-1]
end
end
Thanks,
Richard