From: Tobias Reif Date: 2002-01-14T07:39:29+09:00 Subject: Re: MetaRuby : RubySchema.rb howto? Mathieu Bouchard wrote: > What you want would look like this: > > x.to_ruby > #==> 2.+(2) looking good :) >>So where I now have a mess of spaces, newlines, strings etc. >> def make_getter attr_name >> meth_name = to_methodname(attr_name) >> "\n def #{meth_name}\n"+ >> " @attributes['#{attr_name}'].to_s.to_number\n"+ >> " end\n" >> end >> > > this is already nicer: > > def make_getter attr_name > meth_name = to_methodname(attr_name) > %{ > def #{meth_name} > @attributes['#{attr_name}'].to_s.to_number > end > } > end ... true, it's cleaner, but in contrary to the first version depends on indentation. > def make_getter attr_name > sel = to_methodname(attr_name).intern > DefMethod[nil,sel,DefArgs[[],nil,nil], > Body[[ > M[ > M[ > SliceVar[:@attributes,[LAtom[attr_name]],nil], > :to_s,[],nil,nil], > :to_number,[],nil,nil]]]]] > end > > I think you'll still prefer sticking with the text-based version unless > version 0.8 gets _really_ simpler. :) Yep. It looks pretty tedious. > (At least it's not XML.) I don't understand what you mean here. > by the way, I'd like you to be able to do something like this one > day: > > def make_getter attr_name > meth_name = to_methodname(attr_name) > %c{ > def %u{meth_name} > @attributes[%u{LAtom[attr_name]}].to_s.to_number > end > } > end > > Where %c{} and %u{} would be similar to %{} and #{} except that %c{} would > generate code-objects, not strings. Thus I then can generate code objects by having code parsed, then I can manipulate the whole construct via many useful methods, and then I can get it serialized/written out, nicely laid out. And then I can sit there and smile, if I understood your idea correctly :) Tobi -- http://www.pinkjuice.com/