On Tue, 27 Feb 2001, David Alan Black wrote:

> On Tue, 27 Feb 2001, Joseph McDonald wrote:
> 
> > 
> > Is there a shortcut like:
> > if ((command) = part =~ /#{@pre}\s*(.*?)\s*#{@post}$/s) 
> > 	puts "command: #{command}"
> > end
> > 
> > instead of:
> > 
> > if (part =~ /#{@pre}\s*(.*?)\s*#{@post}$/s) 
> > 	command = $1
> > 	puts "command: #{command}"
> > end
> 
> Try this:
> 
> command = /#{@pre}\s*(.*?)\s*#{@post}$/s.match(part)[1]
> puts "command: #{command}" if command


The only thing is... I now realize, it won't work if there's
no match, because then you're sending "[1]" to nil.

You could try

  command = /#{@pre}\s*(.*?)\s*#{@post}$/s.match(part).to_a[1]

though that seems a little inelegant....


David


-- 
David Alan Black
home: dblack / candle.superlink.net
work: blackdav / shu.edu
Web:  http://pirate.shu.edu/~blackdav