Class: Array

Inherits:
Object
  • Object
show all
Defined in:
lib/safestruct.rb

Class Method Summary collapse

Class Method Details

.of(klass_or_proto_value, size = 0) ⇒ Object

“typed” safe array “constructor” e.g. Array.of( Address ) or Array.of( Money ) or

Array.of( Proposal, 2 ) etc.


82
83
84
85
86
87
88
# File 'lib/safestruct.rb', line 82

def self.of( klass_or_proto_value, size=0 )
  ## note: for nested Hash.of or Array.of a ("prototype") object
  ##        gets passed in (NOT class) - auto-convert to use class
  klass_value = klass_or_proto_value.is_a?( Class ) ? klass_or_proto_value : klass_or_proto_value.class
  klass = Safe::SafeArray.build_class( klass_value, size )
  klass.new
end