B
Bauduin Raphael
I saw in the pickaxe there's a way to call methods dynamically, with
send("method_name"):
"test".send("length") # 4
What I want to do is set a variable this way. Is it possible?
I'm working on a translation tool for a website. rows returned
are of the form:
["id", "language", "value"]
the value of the language field is the identical to the member variable
that will contain the row (wrapped in an object actually).
I thought of something like this:
class Term
attr :query, :fr, :nl, :en
def initialize(dbh, id)
@query = "select * from translations where id='#{id}'"
dbh.select_all(query) do |row|
self.send(row[1].to_s)=Translation.new(row)
end
end
def get_french()
@fr.value
end
end
But that isn't accepted.
Does anyone have the solution?
Thanks
Raph
send("method_name"):
"test".send("length") # 4
What I want to do is set a variable this way. Is it possible?
I'm working on a translation tool for a website. rows returned
are of the form:
["id", "language", "value"]
the value of the language field is the identical to the member variable
that will contain the row (wrapped in an object actually).
I thought of something like this:
class Term
attr :query, :fr, :nl, :en
def initialize(dbh, id)
@query = "select * from translations where id='#{id}'"
dbh.select_all(query) do |row|
self.send(row[1].to_s)=Translation.new(row)
end
end
def get_french()
@fr.value
end
end
But that isn't accepted.
Does anyone have the solution?
Thanks
Raph