# $Id: regexp.rb,v 1.8 2003/04/22 06:13:48 knu Exp $

require 'features/ruby18/base'

class Regexp
  def eql?(o)
    o.is_a?(Regexp) && source.eql?(o.source)
  end

  def hash
    source.hash
  end

  def options
    str = inspect
    pos = str.rindex(?/) + 1

    options = 0
    options |= Regexp::IGNORECASE if casefold?	# str.index(?i, pos)
    options |= Regexp::EXTENDED if str.index(?x, pos)
    options |= Regexp::MULTILINE if str.index(?m, pos)
    options
  end

=begin
  def to_s
    str = inspect
    pos = str.rindex(?/) + 1

    optx = ''
    opty = ''

    'mix'.each_byte { |c|
      (str.index(c, pos) ? optx : opty) << c
    }

    sprintf '(?%s%s:%s)',
      optx,
      opty.empty? ? '' : '-' << opty,
      source()
  end
=end
end

class MatchData
  def select(*x, &block)
    if block
      to_a.select { |s| block.call(s) }
    else
      x.collect { |i| self[i] }
    end
  end
end
