y_support 2.1.18 → 2.4.4
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/y_support/all.rb +2 -32
- data/lib/y_support/core_ext/array.rb +2 -2
- data/lib/y_support/core_ext/class.rb +2 -2
- data/lib/y_support/core_ext/enumerable.rb +2 -2
- data/lib/y_support/core_ext/hash/misc.rb +23 -10
- data/lib/y_support/core_ext/hash.rb +2 -2
- data/lib/y_support/core_ext/module/misc.rb +9 -0
- data/lib/y_support/core_ext/module.rb +2 -2
- data/lib/y_support/core_ext/numeric.rb +2 -2
- data/lib/y_support/core_ext/object/inspection.rb +8 -2
- data/lib/y_support/core_ext/object.rb +3 -3
- data/lib/y_support/core_ext/string/misc.rb +9 -12
- data/lib/y_support/core_ext/string.rb +2 -2
- data/lib/y_support/core_ext/symbol.rb +2 -2
- data/lib/y_support/core_ext.rb +1 -1
- data/lib/y_support/flex_coerce/class_methods.rb +49 -0
- data/lib/y_support/flex_coerce/flex_proxy.rb +121 -0
- data/lib/y_support/flex_coerce/module_methods.rb +37 -0
- data/lib/y_support/flex_coerce.rb +24 -0
- data/lib/y_support/kde.rb +1 -1
- data/lib/y_support/literate.rb +253 -0
- data/lib/y_support/local_object.rb +1 -1
- data/lib/y_support/name_magic/array_methods.rb +48 -0
- data/lib/y_support/name_magic/class_methods.rb +205 -161
- data/lib/y_support/name_magic/hash_methods.rb +33 -0
- data/lib/y_support/name_magic/namespace.rb +449 -0
- data/lib/y_support/name_magic.rb +358 -100
- data/lib/y_support/null_object.rb +1 -1
- data/lib/y_support/respond_to.rb +1 -1
- data/lib/y_support/stdlib_ext/matrix/misc.rb +2 -2
- data/lib/y_support/stdlib_ext/matrix.rb +2 -2
- data/lib/y_support/stdlib_ext.rb +1 -1
- data/lib/y_support/typing/array.rb +1 -1
- data/lib/y_support/typing/enumerable.rb +1 -1
- data/lib/y_support/typing/hash.rb +1 -1
- data/lib/y_support/typing/module.rb +1 -1
- data/lib/y_support/typing/object/typing.rb +17 -15
- data/lib/y_support/typing/object.rb +1 -1
- data/lib/y_support/typing.rb +14 -10
- data/lib/y_support/unicode.rb +1 -1
- data/lib/y_support/version.rb +1 -1
- data/lib/y_support/x.rb +2 -1
- data/test/flex_coerce_test.rb +134 -0
- data/test/literate_test.rb +231 -0
- data/test/misc_test.rb +49 -27
- data/test/name_magic_test.rb +907 -60
- data/test/typing_test.rb +7 -7
- metadata +14 -13
- data/lib/y_support/abstract_algebra.rb +0 -234
- data/lib/y_support/name_magic/array.rb +0 -38
- data/lib/y_support/name_magic/hash.rb +0 -31
- data/lib/y_support/name_magic/namespace_methods.rb +0 -260
- data/lib/y_support/try.rb +0 -133
- data/test/abstract_algebra_test.rb +0 -138
- data/test/performance_test_example.rb +0 -23
- data/test/try_test.rb +0 -102
data/test/typing_test.rb
CHANGED
@@ -103,7 +103,7 @@ describe "y_support/typing" do
|
|
103
103
|
assert_equal( {}, {}.aT_blank )
|
104
104
|
end
|
105
105
|
|
106
|
-
it "should have #aT_present
|
106
|
+
it "should have #aT_present validator" do
|
107
107
|
-> { nil.aT_present }.must_raise TypeError
|
108
108
|
assert 0.aT_present
|
109
109
|
assert_equal( "hello", "hello".aT_present )
|
@@ -116,29 +116,29 @@ describe "y_support/typing" do
|
|
116
116
|
assert [1, 2, 4].aT_all { |e| e < 5 }
|
117
117
|
end
|
118
118
|
|
119
|
-
it "should have #aT_all_kind_of
|
119
|
+
it "should have #aT_all_kind_of validator" do
|
120
120
|
-> { [1.0, 2.0, :a].aT_all_kind_of Numeric }.must_raise TypeError
|
121
121
|
assert [1.0, 2.0, 3].aT_all_kind_of Numeric
|
122
122
|
end
|
123
123
|
|
124
|
-
it "should have #aT_all_comply class compliance
|
124
|
+
it "should have #aT_all_comply class compliance validator" do
|
125
125
|
-> { [1.0, 2.0, :a].aT_all_comply Numeric }.must_raise TypeError
|
126
126
|
assert [1.0, 2.0, 3].aT_all_comply Numeric
|
127
127
|
end
|
128
128
|
|
129
|
-
it "should have #aT_all_numeric
|
129
|
+
it "should have #aT_all_numeric validator" do
|
130
130
|
-> { [:a].aT_all_numeric }.must_raise TypeError
|
131
131
|
assert [1, 2.0].aT_all_numeric
|
132
132
|
end
|
133
133
|
|
134
|
-
it "should have #aT_subset_of
|
134
|
+
it "should have #aT_subset_of validator" do
|
135
135
|
-> { [6].aT_subset_of [*0..5] }.must_raise TypeError
|
136
136
|
assert [1,2].aT_subset_of [*0..5]
|
137
137
|
end
|
138
138
|
end # describe "Enumerable"
|
139
139
|
|
140
140
|
describe "Array" do
|
141
|
-
it "should have #aT_includes (alias #aT_include)
|
141
|
+
it "should have #aT_includes (alias #aT_include) validator" do
|
142
142
|
-> { [1, 2, 4].aT_include 3 }.must_raise TypeError
|
143
143
|
assert [1, 2, 4].aT_include( 4 )
|
144
144
|
assert_equal [6, 7], [6, 7].aT_include( 6 )
|
@@ -185,7 +185,7 @@ describe "y_support/typing" do
|
|
185
185
|
assert_equal( { a: 'a', c: 'b', k: 'k' }, a )
|
186
186
|
end
|
187
187
|
|
188
|
-
it "should have #aT_has synonymizing
|
188
|
+
it "should have #aT_has synonymizing validator" do
|
189
189
|
a = { infile: 'a', csv_out_file: 'b', k: 'k', o: 'k', t: 'k' }
|
190
190
|
assert_respond_to a, :aT_has
|
191
191
|
old = a.dup
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: y_support
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.4.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- boris
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-06-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -80,7 +80,6 @@ files:
|
|
80
80
|
- README.md
|
81
81
|
- Rakefile
|
82
82
|
- lib/y_support.rb
|
83
|
-
- lib/y_support/abstract_algebra.rb
|
84
83
|
- lib/y_support/all.rb
|
85
84
|
- lib/y_support/core_ext.rb
|
86
85
|
- lib/y_support/core_ext/array.rb
|
@@ -102,21 +101,25 @@ files:
|
|
102
101
|
- lib/y_support/core_ext/string/misc.rb
|
103
102
|
- lib/y_support/core_ext/symbol.rb
|
104
103
|
- lib/y_support/core_ext/symbol/misc.rb
|
104
|
+
- lib/y_support/flex_coerce.rb
|
105
|
+
- lib/y_support/flex_coerce/class_methods.rb
|
106
|
+
- lib/y_support/flex_coerce/flex_proxy.rb
|
107
|
+
- lib/y_support/flex_coerce/module_methods.rb
|
105
108
|
- lib/y_support/inert_recorder.rb
|
106
109
|
- lib/y_support/kde.rb
|
110
|
+
- lib/y_support/literate.rb
|
107
111
|
- lib/y_support/local_object.rb
|
108
112
|
- lib/y_support/misc.rb
|
109
113
|
- lib/y_support/name_magic.rb
|
110
|
-
- lib/y_support/name_magic/
|
114
|
+
- lib/y_support/name_magic/array_methods.rb
|
111
115
|
- lib/y_support/name_magic/class_methods.rb
|
112
|
-
- lib/y_support/name_magic/
|
113
|
-
- lib/y_support/name_magic/
|
116
|
+
- lib/y_support/name_magic/hash_methods.rb
|
117
|
+
- lib/y_support/name_magic/namespace.rb
|
114
118
|
- lib/y_support/null_object.rb
|
115
119
|
- lib/y_support/respond_to.rb
|
116
120
|
- lib/y_support/stdlib_ext.rb
|
117
121
|
- lib/y_support/stdlib_ext/matrix.rb
|
118
122
|
- lib/y_support/stdlib_ext/matrix/misc.rb
|
119
|
-
- lib/y_support/try.rb
|
120
123
|
- lib/y_support/typing.rb
|
121
124
|
- lib/y_support/typing/array.rb
|
122
125
|
- lib/y_support/typing/array/typing.rb
|
@@ -131,17 +134,16 @@ files:
|
|
131
134
|
- lib/y_support/unicode.rb
|
132
135
|
- lib/y_support/version.rb
|
133
136
|
- lib/y_support/x.rb
|
134
|
-
- test/
|
137
|
+
- test/flex_coerce_test.rb
|
135
138
|
- test/inert_recorder_test.rb
|
136
139
|
- test/kde_test.rb
|
140
|
+
- test/literate_test.rb
|
137
141
|
- test/local_object_test.rb
|
138
142
|
- test/misc_test.rb
|
139
143
|
- test/misc_test/test_module/fixture_class.rb
|
140
144
|
- test/name_magic_test.rb
|
141
145
|
- test/null_object_test.rb
|
142
|
-
- test/performance_test_example.rb
|
143
146
|
- test/respond_to_test.rb
|
144
|
-
- test/try_test.rb
|
145
147
|
- test/typing_test.rb
|
146
148
|
- test/unicode_test.rb
|
147
149
|
- test/x_test.rb
|
@@ -171,17 +173,16 @@ signing_key:
|
|
171
173
|
specification_version: 4
|
172
174
|
summary: Support library used by Y gems.
|
173
175
|
test_files:
|
174
|
-
- test/
|
176
|
+
- test/flex_coerce_test.rb
|
175
177
|
- test/inert_recorder_test.rb
|
176
178
|
- test/kde_test.rb
|
179
|
+
- test/literate_test.rb
|
177
180
|
- test/local_object_test.rb
|
178
181
|
- test/misc_test.rb
|
179
182
|
- test/misc_test/test_module/fixture_class.rb
|
180
183
|
- test/name_magic_test.rb
|
181
184
|
- test/null_object_test.rb
|
182
|
-
- test/performance_test_example.rb
|
183
185
|
- test/respond_to_test.rb
|
184
|
-
- test/try_test.rb
|
185
186
|
- test/typing_test.rb
|
186
187
|
- test/unicode_test.rb
|
187
188
|
- test/x_test.rb
|
@@ -1,234 +0,0 @@
|
|
1
|
-
#encoding: utf-8
|
2
|
-
|
3
|
-
require 'y_support'
|
4
|
-
require 'y_support/null_object'
|
5
|
-
|
6
|
-
# Rudiments of abstract algebra in Ruby.
|
7
|
-
#
|
8
|
-
# Some objects (users, mixins...) might ask from other classes to have things
|
9
|
-
# defined such as operators #+, #*, or to have a specific instance that behaves
|
10
|
-
# additive identity element (ie. zero), or multiplicative identity element (ie.
|
11
|
-
# one). The essence of some of these requirements is captured by the abstract
|
12
|
-
# algebraic notions of magma, monoid, ring, field...
|
13
|
-
#
|
14
|
-
# At the moment being, y_support/abstract_algebra does not aim as high as to
|
15
|
-
# comprehensively support monoids, rings, fields and the plethora of abstract
|
16
|
-
# algebraic stuff. Support is provided to such degree, as to make some practical
|
17
|
-
# problems tractable. (Our original concern was with Matrix instances filled
|
18
|
-
# with non-numeric objects, whose #+ operator was not coercible to work with
|
19
|
-
# numerics.)
|
20
|
-
#
|
21
|
-
|
22
|
-
# Adds abstract algebra concepts to Ruby.
|
23
|
-
#
|
24
|
-
module Algebra
|
25
|
-
# A Monoid requires:
|
26
|
-
#
|
27
|
-
# Closed and associative addition: #add method
|
28
|
-
# Additive identity element: #additive_identity
|
29
|
-
#
|
30
|
-
module Monoid
|
31
|
-
def self.included receiver
|
32
|
-
receiver.extend self::ClassMethods
|
33
|
-
end
|
34
|
-
|
35
|
-
def + summand; add summand end
|
36
|
-
|
37
|
-
module ClassMethods
|
38
|
-
def zero; additive_identity end
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
# A group is a monoid with additive inverse.
|
43
|
-
#
|
44
|
-
# additive inversion: #additive_inverse
|
45
|
-
#
|
46
|
-
module Group
|
47
|
-
include Monoid
|
48
|
-
def -@; additive_inverse end
|
49
|
-
def - subtrahend; add subtrahend.additive_inverse end
|
50
|
-
end
|
51
|
-
|
52
|
-
# A group that fulfills the condition of commutativity
|
53
|
-
#
|
54
|
-
# ( a.add b == b.add a ).
|
55
|
-
#
|
56
|
-
module AbelianGroup
|
57
|
-
include Group
|
58
|
-
end
|
59
|
-
|
60
|
-
# A ring is a commutative group with multiplication.
|
61
|
-
#
|
62
|
-
# multiplication: #multiply (associative, distributive)
|
63
|
-
# multiplicative identity element: #multiplicative_identity
|
64
|
-
#
|
65
|
-
module Ring
|
66
|
-
include AbelianGroup
|
67
|
-
def * multiplicand; multiply multiplicand end
|
68
|
-
def one; multiplicative_identity end
|
69
|
-
end
|
70
|
-
|
71
|
-
# A field is a ring that can do division.
|
72
|
-
#
|
73
|
-
module Field
|
74
|
-
include Ring
|
75
|
-
def inverse; multiplicative_inverse end
|
76
|
-
def / divisor; multiply divisor.multiplicative_inverse end
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
|
81
|
-
# Patching Integer with Algebra::Ring compliance methods.
|
82
|
-
#
|
83
|
-
class << Integer
|
84
|
-
def additive_identity; 0 end
|
85
|
-
alias zero additive_identity
|
86
|
-
def add( other ); self + other end
|
87
|
-
def additive_inverse; -self end
|
88
|
-
def multiply( other ); self * other end
|
89
|
-
def multiplicative_identity; 1 end
|
90
|
-
alias one multiplicative_identity
|
91
|
-
end
|
92
|
-
|
93
|
-
# Patching Float with Algebra::Field compliance methods.
|
94
|
-
#
|
95
|
-
class << Float
|
96
|
-
def additive_identity; 0.0 end
|
97
|
-
alias zero additive_identity
|
98
|
-
def add( other ); self + other end
|
99
|
-
def additive_inverse; -self end
|
100
|
-
def multiply( other ); self * other end
|
101
|
-
def multiplicative_identity; 1.0 end
|
102
|
-
alias one multiplicative_identity
|
103
|
-
def multiplicative_inverse; 1.0 / self end
|
104
|
-
end
|
105
|
-
|
106
|
-
# Patching Rational with Algebra::Field compliance methods.
|
107
|
-
#
|
108
|
-
class << Rational
|
109
|
-
def additive_identity; Rational 0, 1 end
|
110
|
-
alias zero additive_identity
|
111
|
-
def add( other ); self + other end
|
112
|
-
def additive_inverse; -self end
|
113
|
-
def multiply( other ); self * other end
|
114
|
-
def multiplicative_identity; Rational 1, 1 end
|
115
|
-
alias one multiplicative_identity
|
116
|
-
def multiplicative_inverse; Rational( 1, 1 ) / self end
|
117
|
-
end
|
118
|
-
|
119
|
-
# Patching Complex with #zero method.
|
120
|
-
#
|
121
|
-
class << Complex
|
122
|
-
def additive_identity; Complex 0.0, 0.0 end
|
123
|
-
alias zero additive_identity
|
124
|
-
def add( other ); self + other end
|
125
|
-
def additive_inverse; -self end
|
126
|
-
def multiply( other ); self * other end
|
127
|
-
def multiplicative_identity; Complex 1, 0 end
|
128
|
-
alias one multiplicative_identity
|
129
|
-
def multiplicative_inverse; Complex( 1, 0 ) / self end
|
130
|
-
end
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
# Wildcard zero, stronger than ordinary numeric literal 0.
|
135
|
-
#
|
136
|
-
( WILDCARD_ZERO = NullObject.new ).instance_exec {
|
137
|
-
ɪ = self
|
138
|
-
singleton_class.class_exec { define_method :zero do ɪ end }
|
139
|
-
def * other; other.class.zero end
|
140
|
-
def / other
|
141
|
-
self unless other.zero?
|
142
|
-
fail ZeroDivisionError, "The divisor is zero! (#{other})"
|
143
|
-
end
|
144
|
-
def + other; other end
|
145
|
-
def - other; -other end
|
146
|
-
def coerce other; return other, other.class.zero end
|
147
|
-
def zero?; true end
|
148
|
-
def to_s; "∅" end
|
149
|
-
def inspect; to_s end
|
150
|
-
def to_f; 0.0 end
|
151
|
-
def to_i; 0 end
|
152
|
-
def == other
|
153
|
-
z = begin
|
154
|
-
other.class.zero
|
155
|
-
rescue NoMethodError
|
156
|
-
return false
|
157
|
-
end
|
158
|
-
other == z
|
159
|
-
end
|
160
|
-
}
|
161
|
-
|
162
|
-
|
163
|
-
# As a matter of fact, current version of the Matrix class (by Marc-Andre
|
164
|
-
# Lafortune) does not work with physical magnitudes. It is a feature of the
|
165
|
-
# physical magnitudes, that they do not allow themselves summed with plain
|
166
|
-
# numbers or incompatible magnitudes. But current version of Matrix class,
|
167
|
-
# upon matrix multiplication, performs needless addition of the matrix elements
|
168
|
-
# to literal numeric 0.
|
169
|
-
#
|
170
|
-
# The obvious solution is to patch Matrix class so that the needless addition
|
171
|
-
# to literal 0 is no longer performed.
|
172
|
-
#
|
173
|
-
# More systematically, abstract algebra is to be added to Ruby, and Matrix is
|
174
|
-
# to require that its elements comply with monoid, group, ring, field, depending
|
175
|
-
# on the operation one wants to do with such matrices.
|
176
|
-
#
|
177
|
-
class Matrix
|
178
|
-
attr_writer :zero
|
179
|
-
|
180
|
-
def zero
|
181
|
-
if empty? then @zero else self[0, 0] * 0 end
|
182
|
-
end
|
183
|
-
|
184
|
-
# Matrix multiplication.
|
185
|
-
#
|
186
|
-
def * arg # arg is matrix or vector or number
|
187
|
-
case arg
|
188
|
-
when Numeric
|
189
|
-
rows = @rows.map { |row| row.map { |e| e * arg } }
|
190
|
-
return new_matrix rows, column_size
|
191
|
-
when Vector
|
192
|
-
arg = Matrix.column_vector arg
|
193
|
-
result = self * arg
|
194
|
-
return result.column 0
|
195
|
-
when Matrix
|
196
|
-
Matrix.Raise ErrDimensionMismatch if column_size != arg.row_size
|
197
|
-
if empty? then # if empty?, then reduce uses WILDCARD_ZERO
|
198
|
-
rows = Array.new row_size do |i|
|
199
|
-
Array.new arg.column_size do |j|
|
200
|
-
( 0...column_size ).reduce WILDCARD_ZERO do |sum, c|
|
201
|
-
sum + arg[c, j] * self[i, c]
|
202
|
-
end
|
203
|
-
end
|
204
|
-
end
|
205
|
-
else # if non-empty, reduce proceeds without WILDCARD_ZERO
|
206
|
-
rows = Array.new row_size do |i|
|
207
|
-
Array.new arg.column_size do |j|
|
208
|
-
( 0...column_size ).map { |c| arg[c, j] * self[i, c] }.reduce :+
|
209
|
-
end
|
210
|
-
end
|
211
|
-
end
|
212
|
-
return new_matrix( rows, arg.column_size )
|
213
|
-
when ( SY::Magnitude rescue :SY_Magnitude_absent ) # newly added - multiplication by a magnitude
|
214
|
-
# I am not happy with this explicit switch on SY::Magnitude type here.
|
215
|
-
# Perhaps coerce should handle this?
|
216
|
-
rows = Array.new row_size do |i|
|
217
|
-
Array.new column_size do |j|
|
218
|
-
self[i, j] * arg
|
219
|
-
end
|
220
|
-
end
|
221
|
-
return self.class[ *rows ]
|
222
|
-
else
|
223
|
-
compat_1, compat_2 = arg.coerce self
|
224
|
-
return compat_1 * compat_2
|
225
|
-
end
|
226
|
-
end
|
227
|
-
|
228
|
-
# Creates a matrix of prescribed dimensions filled with wildcard zeros.
|
229
|
-
#
|
230
|
-
def Matrix.wildcard_zero r_count, c_count=r_count
|
231
|
-
build r_count, c_count do |r, c| WILDCARD_ZERO end
|
232
|
-
end
|
233
|
-
end
|
234
|
-
|
@@ -1,38 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
class Array
|
4
|
-
# Maps an array of some objects into an array of their names, obtained by
|
5
|
-
# applying +#full_name+ method to them. Takes one optional argument, which
|
6
|
-
# regulates its behavior regarding unnamed objects. If set to _nil_ (default),
|
7
|
-
# unnamed
|
8
|
-
# objects will be mapped to _nil_ (default behavior of the +#name+ method).
|
9
|
-
# If set to _true_, unnamed objects will be mapped to themselves. If set to
|
10
|
-
# _false_, unnamed objects will not be mapped at all -- the returned array will
|
11
|
-
# contain only the names of the named objects.
|
12
|
-
#
|
13
|
-
def names option=nil
|
14
|
-
return map &:name if option.nil? # unnamed --> nil
|
15
|
-
return map { |e| e.name || e } if option == true # unnamed --> instance
|
16
|
-
return map( &:name ).compact if option == false # unnamed squeezed out
|
17
|
-
fail ArgumentError, "Unknown option: #{option}"
|
18
|
-
end
|
19
|
-
# FIXME: The remaining thing to do to achieve compatibility with Ruby's #name
|
20
|
-
# is to put "full_name" in the body, and "name" in the alias...
|
21
|
-
alias full_names names
|
22
|
-
|
23
|
-
# Maps an array to an array of the element names, obtained by applying
|
24
|
-
# +#_name_+ method to them. Takes one optional argument, which regulates its
|
25
|
-
# behavior regarding unnamed objects. If set to _nil_ (default) unnamed
|
26
|
-
# objects will be mapped to _nil_ (default behavior of +#_name_+ method). If
|
27
|
-
# set to _true_, unnamed objects will be mapped to themselves. If set to
|
28
|
-
# _false_, unnamed objects will not be mapped at all -- the returned array
|
29
|
-
# will contain only the names of the named objects.
|
30
|
-
#
|
31
|
-
def _names_ option=nil
|
32
|
-
return map &:_name_ if option.nil? # unnamed --> nil
|
33
|
-
return map { |e| e.name || e } if option == true # unnamed --> instance
|
34
|
-
return map( &:_name_ ).compact if option == false # unnamed squeezed out
|
35
|
-
fail ArgumentError, "Unknown option: #{option}"
|
36
|
-
end
|
37
|
-
alias ɴs _names_
|
38
|
-
end
|
@@ -1,31 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
class Hash
|
4
|
-
# Maps the hash into one whose keys have been replaced with full names of
|
5
|
-
# the keys (which are assumed to be objects responding to +#full_name+ method).
|
6
|
-
#
|
7
|
-
def keys_to_names # FIXME: Change to keys_to_full_names
|
8
|
-
with_keys do |key| key.name || key end # FIXME: Change name to full_name
|
9
|
-
end
|
10
|
-
|
11
|
-
# Modifies a hash in place so that the keys are replaced with key names (key
|
12
|
-
# objects are assumed to respond to +#name+ method).
|
13
|
-
#
|
14
|
-
def keys_to_names! # FIXME: Change to keys_to_full_names!
|
15
|
-
with_keys! do |key| key.name || key end # FIXME: Change name to full_name
|
16
|
-
end
|
17
|
-
|
18
|
-
# Maps a hash into a hash, whose keys have been replaced with names of the
|
19
|
-
# key objects (which are assumed to respond to +#name+ method).
|
20
|
-
#
|
21
|
-
def keys_to_ɴs
|
22
|
-
with_keys do |key| key._name_ || key end
|
23
|
-
end
|
24
|
-
|
25
|
-
# Modifies a hash in place so that the keys are replaced with key names (key
|
26
|
-
# objects are assumed to respond to +#name+ method).
|
27
|
-
#
|
28
|
-
def keys_to_ɴs!
|
29
|
-
with_keys! do |key| key._name_ || key end
|
30
|
-
end
|
31
|
-
end
|