Class: Rstruct::StructBuilder
- Inherits:
-
Object
- Object
- Rstruct::StructBuilder
- Defined in:
- lib/rstruct/struct_builder.rb
Instance Attribute Summary collapse
-
#__fields ⇒ Object
readonly
Returns the value of attribute __fields.
-
#__registry ⇒ Object
readonly
Returns the value of attribute __registry.
Instance Method Summary collapse
- #array(name, typ, count, opts = {}, &block) ⇒ Object
- #field(name, typ, typ_name, *args, &block) ⇒ Object
-
#initialize(registry = nil, &block) ⇒ StructBuilder
constructor
A new instance of StructBuilder.
- #method_missing(typ_arg, *args, &block) ⇒ Object
Constructor Details
#initialize(registry = nil, &block) ⇒ StructBuilder
Returns a new instance of StructBuilder.
10 11 12 13 14 |
# File 'lib/rstruct/struct_builder.rb', line 10 def initialize(registry=nil, &block) @__fields = [] @__registry = registry || Registry::DEFAULT_REGISTRY instance_eval &block end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(typ_arg, *args, &block) ⇒ Object
24 25 26 27 28 29 30 31 |
# File 'lib/rstruct/struct_builder.rb', line 24 def method_missing(typ_arg, *args, &block) name = args.shift unless typ = @__registry.get(typ_arg) raise(InvalidTypeError, "invalid field type: #{typ_arg}") end field(name, typ, typ_arg, *args, &block) end |
Instance Attribute Details
#__fields ⇒ Object (readonly)
Returns the value of attribute __fields.
8 9 10 |
# File 'lib/rstruct/struct_builder.rb', line 8 def __fields @__fields end |
#__registry ⇒ Object (readonly)
Returns the value of attribute __registry.
8 9 10 |
# File 'lib/rstruct/struct_builder.rb', line 8 def __registry @__registry end |