Method: BitStruct::Vector.struct_class

Defined in:
lib/bit-struct/vector.rb

.struct_class(cl = nil) ⇒ Object

Called as a class method with a single argument in a user-defined subclass to specify a particular BitStruct class to use for each entry, instead of generating an anonymous class. Called without arguments to access the struct class, generating an anonymous one if needed. The struct_class inherits from the struct_class of the parent Vector class.



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/bit-struct/vector.rb', line 32

def struct_class cl = nil
  if cl
    if @struct_class
      warn "changing struct_class in #{self} to #{cl}"
    end
    @struct_class = cl
    @struct_class.default_options default_options
  else
    unless @struct_class
      @struct_class = self == BitStruct::Vector ? BitStruct :
        Class.new(superclass.struct_class)
      @struct_class.default_options default_options
    end
  end
  @struct_class
end