array_2d_simple 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +7 -10
- data/lib/array_2d_simple/version.rb +1 -1
- metadata +1 -1
data/README.md
CHANGED
@@ -20,22 +20,23 @@ Or install it without using Gemfile as:
|
|
20
20
|
|
21
21
|
Initalization:
|
22
22
|
You must:
|
23
|
+
|
23
24
|
require 'array_2d_simple.rb'
|
24
25
|
|
25
26
|
And within your model:
|
27
|
+
|
26
28
|
include Array2dSimple
|
27
29
|
|
28
30
|
There are 2 ways of putting data in the 2D Array:
|
29
|
-
|
30
|
-
|
31
|
-
2. By passing a block to #set_each(see below)
|
31
|
+
1. By iterating with #set_by_rc
|
32
|
+
2. By passing a block to #set_each(see below)
|
32
33
|
|
33
34
|
|
34
35
|
##Example: A board for tic-tac-toe
|
35
36
|
|
36
37
|
require 'array_2d_simple.rb'
|
37
38
|
|
38
|
-
class
|
39
|
+
class TicTacToe
|
39
40
|
include Array2dSimple
|
40
41
|
|
41
42
|
def initialize
|
@@ -45,13 +46,9 @@ There are 2 ways of putting data in the 2D Array:
|
|
45
46
|
|
46
47
|
To fill board with numbers 1-9 and output:
|
47
48
|
|
48
|
-
|
49
|
-
@board.set_each{ |r, c| r*3 + c+1}
|
50
|
-
end
|
49
|
+
@board.set_each{ |r, c| r*3 + c+1}
|
51
50
|
|
52
|
-
|
53
|
-
@board.output
|
54
|
-
end
|
51
|
+
@board.output
|
55
52
|
|
56
53
|
|
57
54
|
## Contributing
|