Glenn wrote:
> Thanks for your help, guys.  All three suggestions are great.
> 
> It seems to me that returning an empty array instead of nil is actually 
> better.

I'd be inclined to agree, although some might argue that a test for nil 
is easier.

class String
  def containedby(startmark='a',endmark='b')
    x=self.scan(Regexp.new(Regexp.escape(startmark)+'([^'+Regexp.escape(endmark)+']*)'+Regexp.escape(endmark))).flatten
    x.size > 0 ? x : nil
  end
end

would return the error conditions as nil.

Mac
-- 
Posted via http://www.ruby-forum.com/.