Sha256: 7a9c8f51f5cb0c96ab504ca91c8721c77f4ba08facbbe887855f78cc79afc45e
Contents?: true
Size: 597 Bytes
Versions: 6
Compression:
Stored size: 597 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 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
6 entries across 6 versions & 2 rubygems