Forum: Ruby Ruby to JSON - how to store javascript functions

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
F50f5d582d76f98686da34917531fe56?d=identicon&s=25 Peter Szinek (Guest)
on 2008-12-02 20:43
(Received via mailing list)
Hey guys,

I am working on a small plug-in which stores settings in a yaml file,
e.g.:

---
:before: var lastsel2;
:params:
   :url: http://www.google.com
   :datatype: xml
   :mtype: GET

etc., then later turning them into js with something like

params.each do |key,value|
   emit "#{key}:  #{value.to_json}
end

so far so good. My question is, what should I put in the place of ???

:params:
   :some_func: ???

so that the Ruby code above spits out this:

some_func: function(id) {
     do_some_stuff
     do_something_else
   }

I hope it's clear :-) Obviously I'd like to store the function params
and body as well.
Is there a (semi-)standard way of doing this? I thought of
representing the js function with some custom class, storing the param
list and body as strings. Am I completely off?

Cheers,
Peter
___
http://www.rubyrailways.com
http://scrubyt.org
This topic is locked and can not be replied to.