restricted_array 0.0.100 → 0.10.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/restrictedarray.rb +32 -21
- metadata +3 -2
data/lib/restrictedarray.rb
CHANGED
@@ -1,24 +1,35 @@
|
|
1
1
|
class RestrictedArray
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
end
|
9
|
-
@array = []
|
10
|
-
@array.push(item)
|
11
|
-
@item_class = item.class
|
2
|
+
attr_reader :array, :item_class, :strict
|
3
|
+
def initialize(item, strict=true)
|
4
|
+
if not strict
|
5
|
+
def item_class=(clazz)
|
6
|
+
@item_class = clazz
|
7
|
+
end
|
12
8
|
end
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
9
|
+
@array = []
|
10
|
+
@array.push(item)
|
11
|
+
@item_class = item.class
|
12
|
+
end
|
13
|
+
def push(item)
|
14
|
+
if item.is_a? @item_class
|
15
|
+
@array.push(item)
|
16
|
+
else
|
17
|
+
raise "Item is not of type #{@item_class}"
|
19
18
|
end
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
end
|
24
|
-
|
19
|
+
end
|
20
|
+
def each(&block)
|
21
|
+
@array.each &block
|
22
|
+
end
|
23
|
+
def map(&block)
|
24
|
+
@array.map &block
|
25
|
+
end
|
26
|
+
def collect(&block)
|
27
|
+
@array.collect &block
|
28
|
+
end
|
29
|
+
def to_s
|
30
|
+
@array
|
31
|
+
end
|
32
|
+
def to_a
|
33
|
+
@array
|
34
|
+
end
|
35
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: restricted_array
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.10.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -11,7 +11,8 @@ bindir: bin
|
|
11
11
|
cert_chain: []
|
12
12
|
date: 2012-05-21 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
|
-
description: An array that is restricted to instances of one class.
|
14
|
+
description: An array that is restricted to instances of one class. Added to_s and
|
15
|
+
to_a methods, as well as map and collect methods. require 'restrictedarray'
|
15
16
|
email: slmnwise@gmail.com
|
16
17
|
executables: []
|
17
18
|
extensions: []
|