array_2d_simple 0.2.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +34 -3
- data/lib/array_2d_simple/version.rb +1 -1
- metadata +2 -2
data/README.md
CHANGED
@@ -12,16 +12,47 @@ And then execute:
|
|
12
12
|
|
13
13
|
$ bundle
|
14
14
|
|
15
|
-
Or install it
|
15
|
+
Or install it without using Gemfile as:
|
16
16
|
|
17
17
|
$ gem install array_2d_simple
|
18
18
|
|
19
19
|
## Usage
|
20
20
|
|
21
|
-
|
21
|
+
Initalization:
|
22
|
+
You must:
|
23
|
+
require 'array_2d_simple.rb'
|
24
|
+
|
25
|
+
And within your model:
|
26
|
+
include Array2dSimple
|
27
|
+
|
28
|
+
There are 2 ways of putting data in the 2D Array:
|
22
29
|
|
23
30
|
1. By iterating with #set_by_rc
|
24
|
-
2. By passing a block to #set_each
|
31
|
+
2. By passing a block to #set_each(see below)
|
32
|
+
|
33
|
+
|
34
|
+
##Example: A board for tic-tac-toe
|
35
|
+
|
36
|
+
require 'array_2d_simple.rb'
|
37
|
+
|
38
|
+
class Board
|
39
|
+
include Array2dSimple
|
40
|
+
|
41
|
+
def initialize
|
42
|
+
@board = Array2d.new( width:3, height:3 )
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
To fill board with numbers 1-9 and output:
|
47
|
+
|
48
|
+
def fill
|
49
|
+
@board.set_each{ |r, c| r*3 + c+1}
|
50
|
+
end
|
51
|
+
|
52
|
+
def output
|
53
|
+
@board.output
|
54
|
+
end
|
55
|
+
|
25
56
|
|
26
57
|
## Contributing
|
27
58
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: array_2d_simple
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2013-01-13 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|