Forum: Ruby Re: Search an array

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Berger, Daniel (Guest)
on 2006-05-15 20:20
(Received via mailing list)
>
> 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.

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.
Robert K. (Guest)
on 2006-05-16 00:29
(Received via mailing list)
2006/5/15, Berger, Daniel <removed_email_address@domain.invalid>:
> >
> > 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.

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
This topic is locked and can not be replied to.