class RegExpr< Hash end class RegExpr::Segment attr_accessor :value def initialize( val) self. value= val end def to_r() self. value. to_s end def empty?() self. value. nil? end def names() @value. names. flatten. compact end def optimize self. value= self. class. optimize self. value self end class <