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
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
Just wondering, what language has been your main programming language
until now?
I'm always curious to know where the influx of new Ruby programmers are
coming from. I'm from a C++/C#/.Net background and while the syntax is
similar to both C++ and C# some things are definitely a bit different.
"The second thing that Ruby does with double-quoted strings is expression interpolation. Within the string, the sequence #{ expression } is replaced by the value of expression. We could use this to rewrite our previous method.
def sayGoodnight(name)
result = "Goodnight, #{name}"
return result
end
When Ruby constructs this string object, it looks at the current value of name and substitutes it into the string. Arbitrarily complex expressions are allowed in the #{...} construct."
···
On Dec 22, 2005, at 7:32 PM, Joe Van Dyk wrote:
On 12/22/05, redrhodes <richstep911@gmail.com> wrote:
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