> After messing up with racc for a couple of hours I realized > that most of the parse functions look pretty much the same, > so I thought of stretching my metaprogramming muscles and I > wrote my first meta_parse function. > > I would like to hear your comments on it, but please be > gentle ;-) I usually try to avoid those inline strings. I don't like them. As long as you don't pass a block in the call to the dynamically defined method, you can use "define_method" instead. I moved a bit of code and came up with the code below. (Next time, please provide runnable code... ) gegroet, Erik V. - http://www.erikveen.dds.nl/ ---------------------------------------------------------------- require 'strscan' def meta_parse(*ary) self.class.module_eval do define_method :parse do |str| @q = [] scanner = StringScanner.new(str) until scanner.empty? ary.each do |type, exp, meth| if m = scanner.scan(exp) @q << [type, (meth ? m.send(meth) : m)] end end end @q << [false,false] do_parse end end end def do_parse p $q @q end meta_parse [:A, /a/], [:NUMBER, /\d+/, :to_i], [:WS, /(\s|\t)+/] parse("a aaa 12132 ").each{|type,val| puts "#{type}: '#{val}'"} ----------------------------------------------------------------