Skip to content
Provides methods for creating type-enforced Arrays
Ruby
Branch: master
Clone or download
Latest commit 3b92cb3 Oct 5, 2011
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
lib less code Sep 6, 2011
spec remove whitespace, edit some syntax inconsistencies Sep 6, 2011
.document Initial commit to typed-array. Aug 3, 2011
.gitignore non-project-specific ignores should go to $HOME/.gitignore Sep 6, 2011
.rspec Initial commit to typed-array. Aug 3, 2011
Gemfile use gemspec in Gemfile Sep 6, 2011
LICENSE.txt Initial commit to typed-array. Aug 3, 2011
README.rdoc update/format documentation Aug 3, 2011
Rakefile
VERSION Version bump to 0.1.2 Aug 3, 2011
typed-array.gemspec regenerate gemspec Sep 6, 2011

README.rdoc

typed-array

Gem provides enforced-type functionality to Arrays

Copyright © 2011 Ryan Biesemeyer See LICENSE.txt for details

Ryan Biesemeyer 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
You can’t perform that action at this time.