1 2 module Kernel 3 # simple (sequential) enumerated values 4 def enum(*syms) 5 syms.each { |s| const_set(s, s.to_s) } 6 const_set(:DEFAULT, syms.first) unless syms.nil? 7 end 8 end 9 10 //and the usage 11 12 require 'kernel' 13 14 15 16 module Constants 17 18 module Gradient 19 20 enum :DOWNSLOPE, :LEVEL, :UPSLOPE 21 22 end 23 24 25 26 module TreeCover 27 28 enum :GOOD, :BAD, :OK 29 30 end 31 32 33 34 module TrafficDensity 35 36 enum :LOW, :MEDIUM, :HIGH 37 38 end 39 40 end
// simple Enum creation
sbeckeriv posts on Mar 11, 2008 at 13:56
You need to create an account or log in to post comments to this site.