3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
# File 'lib/xdr/dsl/enum.rb', line 3
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 " def self.\#{name}\n members[\"\#{name}\"]\n end\n EOS\nend\n", __FILE__, __LINE__
|