File: README.rdoc

package info (click to toggle)
ruby-typed-array 0.1.2-3
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 128 kB
  • ctags: 28
  • sloc: ruby: 370; makefile: 2
file content (42 lines) | stat: -rw-r--r-- 1,132 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
= typed-array

Gem provides enforced-type functionality to Arrays

Copyright (c) 2011 Ryan Biesemeyer
See LICENSE.txt for details

Ryan Biesemeyer mailto:ruby-dev@yaauie.com

== Example

=== Create Standard Class

 require 'typed-array'
 class Things < Array
   extend TypedArray
   restrict_types Thing1,Thing2
 end
 
=== Generate Class using Factory
 
 require 'typed-array'
 things = TypedArray(Thing1,Thing2)

=== Adding items to the Array
 
 # All standard Array interfaces are implemented, including block-processing
 # and variable-number of arguments. For methods that would usually return an
 # Array, they instead return an instance of the current class (except to_a).
 #
 # The difference is that if the method would generate an Array including the
 # wrong types, TypedArray::UnexpectedTypeException is raised and the call is
 # aborted before modifying the enforced TypedArray instance.
 
 require 'typed-array'
 symbols = TypedArray(Symbol).new([:foo,:bar,:baz,:bingo])
 begin
   integers = TypedArray(Integer).new([1,3,7,2,:symbol])
 rescue TypedArray::UnexpectedTypeException
   puts "An error occured: #{$!}"
 end