I want to have a hash my_statement
as below:
my_statement = %|{:foo=>\#{bar_array}}|
where :foo
is the key and the value is to be substituted with the value of bar_array
later. After I later define bar_array = ["a","b"]
, I do an eval
on this statement, and want it to show the following:
eval(my_statement)
# => {:foo=>["a", "b"]}
I need to escape the variable bar_array
so that it evaluates not when my_statement
is assigned but rather when eval
is called on it. I can't seem to get the escaping of the variable. I tried \#
, #
, \\#
.
The background of why I am doing this: I have several statically defined charts backed by SOLR queries. I took the approach to define these queries in a serializable column in the database (again they "never" change). There are actually two levels of queries; the first level which gets "all" data for that query; and the second level which is based on the user selecting some data (off of a chart) from the first query - i.e., I need a variable to be part of the second query. Sometimes (like in this example) the variable will contain an array.