From: ahoward Date: 2003-05-15T04:46:08+09:00 Subject: Re: ruby_run() w/o exit? On Thu, 15 May 2003 dblack@superlink.net wrote: > Ara, in cases like this you might have to compromise on the boycotting of > parentheses :-) sheesh. first matz, now you. poetry moders unite! i think this was the first (and last!) time i'll post code without running it. you guys keep a fella on his toes! ;-) this is perhaps more appropriate - and it runs: ----CODE---- require 'singleton' class Language class MemoryLeakError < StandardError attr :lang def initialize(lang, *a); @lang = lang; super *a; end end attr :name alias to_s name def initialize name; @name = name; end end class AHoward include Singleton attr :langs def initialize @langs = %w(ruby c perl java idl bash sh zsh tcsh csh fortran c++) @langs.map!{|l| Language.new l.gsub /[+]/, '-'} end def rank lang raise Language::MemoryLeakError.new lang if /--$/.match lang.name raise NotImplementedError unless i = langs.index(lang) return i end end ara = AHoward.instance begin ara.langs.map{|l| puts "%8.8s : %s" % [l, ara.rank l]} rescue Language::MemoryLeakError => leak STDERR.puts "LEAK FROM %s!" % leak.lang raise end ----CODE---- ~/eg/ruby > ruby ahoward.rb ruby : 0 c : 1 perl : 2 java : 3 idl : 4 bash : 5 sh : 6 zsh : 7 tcsh : 8 csh : 9 fortran : 10 LEAK FROM c--! ahoward.rb:23:in `rank': Language::MemoryLeakError (Language::MemoryLeakError) from ahoward.rb:32 from ahoward.rb:32:in `map' from ahoward.rb:32:in `each' from ahoward.rb:32:in `map' from ahoward.rb:32 -a -- ==================================== | Ara Howard | NOAA Forecast Systems Laboratory | Information and Technology Services | Data Systems Group | R/FST 325 Broadway | Boulder, CO 80305-3328 | Email: ara.t.howard@fsl.noaa.gov | Phone: 303-497-7238 | Fax: 303-497-7259 ====================================