Ruby Forum Ruby > Easy code generation in Ruby.

Posted by Patrick Li (cuppojava)
on 19.08.2008 17:33
Hi,
I know how to dynamically create methods and classes in Ruby, but is
there anyway to save these methods to a file?

eg. I'm looking for something like this:
define_method_in_file("File.rb", :myMethod) do
  instance_variable_set(:@a, "myString")
end

to produce:
<File.rb>
def myMethod
  @a = "myString"
end

Thanks a lot for answering. I'm hoping there's something easier than
having to mess about with templates.
  -Patrick
Posted by Jason Roelofs (Guest)
on 19.08.2008 17:44
(Received via mailing list)
On Tue, Aug 19, 2008 at 11:30 AM, Patrick Li 
<patrickli_2001@hotmail.com> wrote:
> <File.rb>
>
You could try ruby2ruby.  http://seattlerb.rubyforge.org/ruby2ruby/

Jason
Posted by Patrick Li (cuppojava)
on 19.08.2008 18:07
That's perfect. Thank you.