From: Mathieu Bouchard Date: 2002-01-12T12:50:03+09:00 Subject: Re: MetaRuby : RubySchema.rb howto? On Sat, 12 Jan 2002, Tobias Reif wrote: > Mathieu Bouchard wrote: > > In RubySchema.rb (my proposed object system for ruby code), > rb = Ruby_program.new(:single_file) There is no RubyProgram class, because any Expr can qualify as a Ruby program. > file.write rb.to_s There is no un-parsing back to Ruby, yet. I want that for next version though. > Found it :) http://hostname.2y.net/~matju/MetaRuby/ > Perhaps I can use it. On Sat, 12 Jan 2002, Tobias Reif wrote: > in a program that generates Ruby programs, I'd like to use MetaRuby's > RubySchema.rb to generate the code. I'm making incompatible changes to it about right now. Its main current purpose is that interested people can look at it and suggest changes. OTOH, the best way you can find out what to suggest is to try to write real programs using it. > include Ruby > ############# > #class DefClass < Tuple; fields_are \ > # [:name,Any.of IdentConst], > # [:supername,IdentConst,NilClass], > # # nil: class Foo; end > # # other: class Foo # [:body,Body] end > ######## DefClass is broken in 0.7; the "Any.of" was supposed to be on the next line. (Any.of is only useful with at least 2 args) > class_def_01 = DefClass.new 'Tobi', nil, nil IdentConst is a special case of Symbol where the first character is an uppercase letter. also, even though supername may be nil, body may not: you have to put at least an empty Body. so that would be: class_def_01 = DefClass[:Tobi, nil, Body[[]]] the .[] is just shortcut for .new() > puts class_def_01.methods You won't be able to do that. ClassDefs don't contain methods directly, they contain MethodDefs (or not) instead. When you will eval the ClassDef (someday), a class would be created with the actual methods in it. If you want to scan class_def_01 for MethodDefs you could do: class_def_01.body.body.find_all {|x| MethodDef===x } Many of the future changes to RubySchema will be introduced in part to reduce verboseness like body.body and [[]] and so on... ________________________________________________________________ Mathieu Bouchard http://hostname.2y.net/~matju