Class: Jsof::WrapArrayType
- Inherits:
-
Object
- Object
- Jsof::WrapArrayType
- Defined in:
- lib/jsof/wrap_array_type.rb
Overview
Used with define_attr to define typed array property.
Instance Method Summary collapse
-
#assignable?(val) ⇒ Boolean
Check value can be wrapped by this type.
-
#initialize(typeof_element: nil) ⇒ WrapArrayType
constructor
A new instance of WrapArrayType.
-
#new(obj) ⇒ Jsof::WrapArray
Create wrapper instance.
Constructor Details
#initialize(typeof_element: nil) ⇒ WrapArrayType
Returns a new instance of WrapArrayType.
5 6 7 |
# File 'lib/jsof/wrap_array_type.rb', line 5 def initialize(typeof_element: nil) @typeof_element = typeof_element end |
Instance Method Details
#assignable?(val) ⇒ Boolean
Check value can be wrapped by this type.
17 18 19 20 21 22 23 |
# File 'lib/jsof/wrap_array_type.rb', line 17 def assignable?(val) if @typeof_element && val return false unless val.is_a? Array return val.all?{|elem| Jsof::WrapHelper.assignable?(@typeof_element, elem)} end true end |
#new(obj) ⇒ Jsof::WrapArray
Create wrapper instance.
11 12 13 |
# File 'lib/jsof/wrap_array_type.rb', line 11 def new(obj) Jsof::WrapArray.new(obj, typeof_element: @typeof_element) end |