Method: Thrift::Union#initialize
- Defined in:
- lib/thrift/union.rb
#initialize(name = nil, value = nil) ⇒ Union
Returns a new instance of Union.
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/thrift/union.rb', line 22 def initialize(name=nil, value=nil) if name if name.is_a? Hash if name.size > 1 raise "#{self.class} cannot be instantiated with more than one field!" end name, value = name.keys.first, name.values.first end if Thrift.type_checking raise Exception, "#{self.class} does not contain a field named #{name}!" unless name_to_id(name.to_s) end if value.nil? raise Exception, "Union #{self.class} cannot be instantiated with setfield and nil value!" end Thrift.check_type(value, struct_fields[name_to_id(name.to_s)], name) if Thrift.type_checking elsif !value.nil? raise Exception, "Value provided, but no name!" end @setfield = name @value = value end |