class Object def iv @_iv ||= {} end def an @_an ||= Hash.new{|k,h| h[k]={:flags=>[]} } end private :iv end class Module def var(*vars) vars.each do |v| class_eval <<-EOS protected def #{v} iv[:#{v}] end def #{v}=(arg) iv[:#{v}] = arg end EOS end #protected "#{s}", "#{s}=" return *vars end def pub(*vars) var *vars public *vars end def publish(*vars) public *vars end def req(*vars) var *vars public *vars.collect{|v| "#{v}="} end def request(*vars) public *vars.collect{|v| "#{v}="} end def rec(*vars) var *vars public *vars public *vars.collect{|v| "#{v}="} end def record(*vars) public *vars public *vars.collect{|v| "#{v}="} end end #__TEST__ #=begin testing if $0 == __FILE__ require 'mega/quicktest' testcase :TC01 do class X var :l pub :r req :w rec :a end def setup @x = X.new end test do assert( @x.r == nil ) assert_equal( 1, @x.w = 1 ) assert_equal( 2, @x.a = 2 ) assert_equal( 2, @x.a ) end end end #=end