Ruby passing different attribute arguments to same function -
I have a job model that has many features I want to use graphics to display the sum of some of these features. I am For this, I am using the following code in the JavaScript section of the scene which produces the graph:
% job @ dell_jose %% & gt; ['& Lt;% = job.day% & gt;', & lt;% = job.walletime%>], & lt;% end% & gt;
Here it returns:
['2010-07-25', 1234], ['2010-07-26', 3456], ['2010-07-27', 1234],
That is working fine, however, I do not want to graph the contribution of only "waltime", but many other fragments For: memory, CPU, etc ... so I have to do such things as:
& lt;% in job @ dell_jose %% & gt; ['& Lt;% = job.day% & gt;', & lt;% = job.cpu% & gt;], & lt;% end% & gt;
and
& lt;% in jobs @ day_jose %% & gt; ['& Lt;% = job.day% & gt;', & lt;% = job.memory% & gt;], & lt;% end% & gt;
To make other graphs, but it is not completely dry, I need a task in which I could pass the contribution as an argument. But I do not know how to do it.
For example:
function (cpu)
will return
[' & Lt;% = Job.day% & gt; ', ,
and
function (walim) > < Code> ['& lt;% = job.day% & gt;', & lt;% = job.walltime%>],
You can do something easier
attr_list = [:
then through jobs Resume from
& lt;% jobs @ daily_jobs% & gt; & Lt;% attr_list.each do | Attr | & Gt%; ['& Lt;% = job.day% & gt;', & lt;% = job.send (attri)%>, & lt;% end% & gt; & Lt;% end% & gt;
Another solution will create a method in the job model such as:
def as_js_attr (attr) "['# {self.day}', # { Increasing the last loop with self.send (attr)}, "ending
and
Comments
Post a Comment