Class: SuperStruct
- Inherits:
-
Struct
- Object
- Struct
- SuperStruct
- Defined in:
- lib/superstruct.rb
Overview
SuperStruct is an enhanced version of the Ruby Standard library Struct.
Compared with the original version, it provides the following additional features:
-
ability to initialize an instance from Hash
-
ability to pass a block on creation
Instance Method Summary collapse
-
#initialize(*args) { ... } ⇒ SuperStruct
constructor
Overwrites the standard Struct initializer to add the ability to create an instance from a Hash of parameters.
Constructor Details
#initialize({ Symbol = > Object }) ⇒ SuperStruct #initialize([ value1, value1, ... ]) ⇒ SuperStruct #initialize(value1, value1, ...) ⇒ SuperStruct
Overwrites the standard Struct initializer to add the ability to create an instance from a Hash of parameters.
34 35 36 37 38 39 40 41 42 43 |
# File 'lib/superstruct.rb', line 34 def initialize(*args) if args.first.is_a? Hash initialize_with_hash(args.first) elsif args.size == 0 super else raise ArgumentError end yield(self) if block_given? end |