# $Id: struct.rb,v 1.2 2002/04/14 19:38:57 knu Exp $

require 'features/ruby18/base'

class Struct
  @@__ruby18_struct_methods = proc {
    def each_pair
      members.each { |m|
	yield(m.intern, self[m])
      }
    end

    def select(*x, &block)
      if block
	# delegate to Enumerable#select
	super(&block)
      else
	x.map { |m|
	  self[m]
	}
      end
    end
  }

  class << self
    alias __ruby16_new new

    def new(*x)
      struct_class = __ruby16_new(*x)
      struct_class.module_eval(&@@__ruby18_struct_methods)
      struct_class
    end
  end
end
