From: Mike Fletcher Date: 2006-05-16T01:08:53+09:00 Subject: Re: Search an array Patrick Spence wrote: > > Given the following scenario... [...] > How can I search the callstack array; $@, for the element that contains > the currently running program; $0? The idea is to log all the errors to > a SQL Server database, the name of the program, line number where the > error occurred, error message, etc. > Slightly modified but basically the same as your scenario, searching $a rather than $@ since it's not amenable to being set directly apparently. irb(main):018:0> pp $0 "C:/mhiqTest/testAdoConnection.rb" => nil irb(main):019:0> pp $a ["c:/ruby/lib/ruby/site_ruby/1.8/DBD/ADO/ADO.rb:57:in `connect'", "c:/ruby/lib/ruby/site_ruby/1.8/dbi.rb:424:in `connect'", "c:/ruby/lib/ruby/site_ruby/1.8/dbi.rb:215:in `connect'", "C:/mhiqTest/testAdoConnection.rb:16"] => nil irb(main):020:0> $a.grep( %r/^#$0/ ) => ["C:/mhiqTest/testAdoConnection.rb:16"] -- Posted via http://www.ruby-forum.com/.