# Ruby to JSON - how to store javascript functions

**URL:** <https://www.ruby-forum.com/t/ruby-to-json-how-to-store-javascript-functions/154673>\
**Category:** Ruby\
**Created:** [December 2, 2008, 8:43pm UTC](https://www.ruby-forum.com/t/ruby-to-json-how-to-store-javascript-functions/154673 "2008-12-02T20:43:50Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![splattael](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/858c86/32.png) [@splattael](https://www.ruby-forum.com/u/splattael)\
**Post date:** [December 2, 2008, 8:43pm UTC](https://www.ruby-forum.com/t/ruby-to-json-how-to-store-javascript-functions/154673/1 "2008-12-02T20:43:50Z")

</div>

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](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://www.rubyrailways.com)  
[http://scrubyt.org](http://scrubyt.org)
