class StructWithType
StructWithType
Public Class Methods
new(*args)
click to toggle source
TODO: document
Calls superclass method
# File lib/el4r/el4r-sub.rb, line 632 def self.new(*args) keys = [] types = [] args.each_with_index do |x,i| if i%2 == 0 keys << x else types << x end end unless keys.length > 0 && types.length > 0 && keys.length == types.length raise ArgumentError, "#{self}: args.length must be even" end klass = super(*keys) klass.instance_eval do @@__type_dic__ = {} @@__keys__ = keys keys.each_with_index{|k,i| @@__type_dic__[k] = types[i]} end klass end
new(*args)
click to toggle source
Calls superclass method
# File lib/el4r/el4r-sub.rb, line 662 def initialize(*args) args.each_with_index do |x, i| args[i] = __convert__(@@__keys__[i], x) end class << self @@__keys__.each do |k| define_method("#{k}="){|v| self[k]=v} end end super *args end
Public Instance Methods
[]=(k,v)
click to toggle source
Calls superclass method
# File lib/el4r/el4r-sub.rb, line 681 def []=(k,v) v = __convert__(k,v) super(k,v) end
Private Instance Methods
__convert__(k,v)
click to toggle source
# File lib/el4r/el4r-sub.rb, line 676 def __convert__(k,v) __send__(@@__type_dic__[k.to_sym],v) end