aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support
diff options
context:
space:
mode:
authorJoshua Peek <josh@joshpeek.com>2008-07-22 11:12:16 -0500
committerJoshua Peek <josh@joshpeek.com>2008-07-22 11:12:16 -0500
commit2681685450631238511cfc3c2f0fa044c1f8033a (patch)
tree2414319c504d25ece84a8cfdce5f2f6c10b13fc8 /activesupport/lib/active_support
parentbc5896e708bf8070835bebe61de03b701fa5e6f7 (diff)
downloadrails-2681685450631238511cfc3c2f0fa044c1f8033a.tar.gz
rails-2681685450631238511cfc3c2f0fa044c1f8033a.tar.bz2
rails-2681685450631238511cfc3c2f0fa044c1f8033a.zip
Extract ActiveSupport::TypedArray class to ensure an array is all of the same type [#673 state:resolved]
Diffstat (limited to 'activesupport/lib/active_support')
-rw-r--r--activesupport/lib/active_support/typed_array.rb31
1 files changed, 31 insertions, 0 deletions
diff --git a/activesupport/lib/active_support/typed_array.rb b/activesupport/lib/active_support/typed_array.rb
new file mode 100644
index 0000000000..1a4d8a8faf
--- /dev/null
+++ b/activesupport/lib/active_support/typed_array.rb
@@ -0,0 +1,31 @@
+module ActiveSupport
+ class TypedArray < Array
+ def self.type_cast(obj)
+ obj
+ end
+
+ def initialize(*args)
+ super(*args).map! { |obj| self.class.type_cast(obj) }
+ end
+
+ def <<(obj)
+ super(self.class.type_cast(obj))
+ end
+
+ def concat(array)
+ super(array.map! { |obj| self.class.type_cast(obj) })
+ end
+
+ def insert(index, obj)
+ super(index, self.class.type_cast(obj))
+ end
+
+ def push(*objs)
+ super(*objs.map { |obj| self.class.type_cast(obj) })
+ end
+
+ def unshift(*objs)
+ super(*objs.map { |obj| self.class.type_cast(obj) })
+ end
+ end
+end