Why look in $@? You already know what $0 is.
Also, it might be easier to use a library like 'tracer' (stdlib) or
perhaps ruby-trace (RAA).
In other other random thoughts, ruby-trace looks like a prime candidate
for a rewrite using a DSL. 
Regards,
Dan
This communication is the property of Qwest and may contain confidential or
privileged information. Unauthorized use of this communication is strictly
prohibited and may be unlawful. If you have received this communication
in error, please immediately notify the sender by reply e-mail and destroy
all copies of the communication and any attachments.
路路路
-----Original Message-----
From: list-bounce@example.com
[mailto:list-bounce@example.com] On Behalf Of Patrick Spence
Sent: Monday, May 15, 2006 9:59 AM
To: ruby-talk ML
Subject: Search an array
Given the following scenario...
$0 = "C:/mhiqTest/testAdoConnection.rb"
$@[0] = "c:/ruby/lib/ruby/site_ruby/1.8/DBD/ADO/ADO.rb:57:in
`connect'" $@[1] =
"c:/ruby/lib/ruby/site_ruby/1.8/dbi.rb:424:in `connect'"
$@[2] = "c:/ruby/lib/ruby/site_ruby/1.8/dbi.rb:215:in
`connect'" $@[3] = "C:/mhiqTest/testAdoConnection.rb:16"
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.
Thanks!
He needs to find the entry with the name to get the line number.
Here's another nice solution:
prog = "C:/mhiqTest/testAdoConnection.rb"
stack = [
"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",
]
rx = Regexp.new(Regexp.escape(prog) + ":(\\d+)")
stack.inject(nil) {|nr, frame| rx =~ frame ? $1.to_i : nr }
:-))
Kind regards
robert
路路路
2006/5/15, Berger, Daniel <Daniel.Berger@qwest.com>:
> -----Original Message-----
> From: list-bounce@example.com
> [mailto:list-bounce@example.com] On Behalf Of Patrick Spence
> Sent: Monday, May 15, 2006 9:59 AM
> To: ruby-talk ML
> Subject: Search an array
>
> Given the following scenario...
>
> $0 = "C:/mhiqTest/testAdoConnection.rb"
>
> $@[0] = "c:/ruby/lib/ruby/site_ruby/1.8/DBD/ADO/ADO.rb:57:in
> `connect'" $@[1] =
> "c:/ruby/lib/ruby/site_ruby/1.8/dbi.rb:424:in `connect'"
> $@[2] = "c:/ruby/lib/ruby/site_ruby/1.8/dbi.rb:215:in
> `connect'" $@[3] = "C:/mhiqTest/testAdoConnection.rb:16"
>
> 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.
>
> Thanks!
Why look in $@? You already know what $0 is.
--
Have a look: Robert K. | Flickr