static-ruby 0.0.2 → 0.0.3
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.
- checksums.yaml +4 -4
- data/lib/static_ruby.rb +106 -3
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1d391534d36cac02a1c1d9f800c84a72f70434a80696b0e75b701af70517891b
|
4
|
+
data.tar.gz: 481c734c0a7c3d1f0eaf3bf9f3e4817fa61cdadb8e81567340501f44af4a3ccd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 45bcc6e77ebcd5aac42a1894bdce457e47930dcb9295baf50a28dca5f1fad5719c073ea2e6183c3477a4b96b767e7bf6724d719336f8bd507ed5ae66908e1902
|
7
|
+
data.tar.gz: 3f890175e8ed1231592461b4d365dd5ecc3a93e760b94a5f13375d8be143e40efb6f968e3c227a0c14f32d32494efdd2684d3c1245d3e526c220a84ecccecb84
|
data/lib/static_ruby.rb
CHANGED
@@ -1,9 +1,112 @@
|
|
1
|
-
Pair
|
1
|
+
class Pair
|
2
|
+
attr_reader :size, :first, :second
|
3
|
+
|
4
|
+
def initialize(first, second)
|
5
|
+
@first = first
|
6
|
+
@second = second
|
7
|
+
@size = 2
|
8
|
+
end
|
9
|
+
|
2
10
|
def to_a
|
3
|
-
[first, second]
|
11
|
+
[@first, @second]
|
4
12
|
end
|
5
13
|
|
6
14
|
def to_s
|
7
|
-
"Pair(#{first} #{second})"
|
15
|
+
"Pair(#{@first} #{@second})"
|
16
|
+
end
|
17
|
+
|
18
|
+
def ==(o)
|
19
|
+
@first == o.first && @second == o.second
|
20
|
+
end
|
21
|
+
|
22
|
+
def !=(o)
|
23
|
+
@first != o.first || @second != o.second
|
24
|
+
end
|
25
|
+
|
26
|
+
def each(&block)
|
27
|
+
block.call(@first)
|
28
|
+
block.call(@second)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
|
33
|
+
class Triple
|
34
|
+
attr_reader :size, :first, :second, :third
|
35
|
+
|
36
|
+
def initialize(first, second, third)
|
37
|
+
@first = first
|
38
|
+
@second = second
|
39
|
+
@third = third
|
40
|
+
@size = 3
|
41
|
+
end
|
42
|
+
|
43
|
+
def to_a
|
44
|
+
[@first, @second, @third]
|
45
|
+
end
|
46
|
+
|
47
|
+
def to_s
|
48
|
+
"Triple(#{@first} #{@second} #{@third})"
|
49
|
+
end
|
50
|
+
|
51
|
+
def ==(o)
|
52
|
+
@first == o.first && @second == o.second && @third == o.third
|
53
|
+
end
|
54
|
+
|
55
|
+
def !=(o)
|
56
|
+
@first != o.first || @second != o.second || @third != o.third
|
57
|
+
end
|
58
|
+
|
59
|
+
def each(&block)
|
60
|
+
block.call(@first)
|
61
|
+
block.call(@second)
|
62
|
+
block.call(@third)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
|
67
|
+
class Tuple
|
68
|
+
attr_reader :size, :elements, :first, :last
|
69
|
+
|
70
|
+
def initialize(*elements)
|
71
|
+
@elements = elements
|
72
|
+
@size = elements.size
|
73
|
+
@first = elements.size != 0 ? elements[0] : nil
|
74
|
+
@last = elements.size != 0 ? elements[-1] : nil
|
75
|
+
end
|
76
|
+
|
77
|
+
def to_a
|
78
|
+
@elements
|
79
|
+
end
|
80
|
+
|
81
|
+
def to_s
|
82
|
+
"Tuple(#{@elements.map { |x| x.to_s }})"
|
83
|
+
end
|
84
|
+
|
85
|
+
def ==(o)
|
86
|
+
@elements == o.elements
|
87
|
+
end
|
88
|
+
|
89
|
+
def !=(o)
|
90
|
+
@elements != o.elements
|
91
|
+
end
|
92
|
+
|
93
|
+
def [](i)
|
94
|
+
@elements[i]
|
95
|
+
end
|
96
|
+
|
97
|
+
def []=(_, _)
|
98
|
+
raise('Tuple cannot be modified')
|
99
|
+
end
|
100
|
+
|
101
|
+
def each(&block)
|
102
|
+
@elements.each do |x|
|
103
|
+
block.call(x)
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
def each_with_index(&block)
|
108
|
+
@elements.each_with_index do |x, i|
|
109
|
+
block.call(x, i)
|
110
|
+
end
|
8
111
|
end
|
9
112
|
end
|