Sha256: d0db1b1770ba457cbebb4ea1a3227c44361818ea51528fc38dcd9378993d13c6
Contents?: true
Size: 663 Bytes
Versions: 1
Compression:
Stored size: 663 Bytes
Contents
module XDR::DSL::Enum def member(name, value) raise ArgumentError, "#{self} is sealed" if self.sealed raise ArgumentError, "#{value} is not Fixnum" unless value.is_a?(Fixnum) raise ArgumentError, "#{value} is not >= 0" unless value >= 0 raise ArgumentError, "#{value} is already used" unless name = name.to_s.underscore instance = new(name, value) self.members = self.members.merge(name => instance) self.by_value = self.by_value.merge(instance.value => instance) class_eval <<-EOS, __FILE__, __LINE__ def self.#{name} members["#{name}"] end EOS end def seal self.sealed = true end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
xdr-0.0.1 | lib/xdr/dsl/enum.rb |