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
- #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.
9 10 11 12 13 |
# File 'lib/rstruct/struct_builder.rb', line 9 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
19 20 21 22 23 24 25 26 |
# File 'lib/rstruct/struct_builder.rb', line 19 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.
7 8 9 |
# File 'lib/rstruct/struct_builder.rb', line 7 def __fields @__fields end |
#__registry ⇒ Object (readonly)
Returns the value of attribute __registry.
7 8 9 |
# File 'lib/rstruct/struct_builder.rb', line 7 def __registry @__registry end |