rdoba 0.9.3 → 0.9.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.
data/lib/rdoba/mixin.rb CHANGED
@@ -1,321 +1,378 @@
1
1
  #!/usr/bin/ruby -KU
2
- #encoding:utf-8
3
-
2
+ # frozen_string_literal: true
3
+
4
4
  class String
5
- # TODO obsolete
6
- ByteByByte = 0
7
- FirstChar = 1
5
+ # TODO: obsolete
6
+ ByteByByte = 0
7
+ FirstChar = 1
8
8
  end
9
9
 
10
10
  module Rdoba
11
- module Mixin
12
- class InvalidOption < StandardError ; end
13
-
14
- module CompareString
15
- def compare_to value, opts = {}
16
- if ( opts == :ignore_diacritics ||
17
- opts.class == Hash && opts.key?( :ignore_diacritics ) )
18
- # TODO verify composite range
19
- def crop_diacritics(x)
20
- (x < 0x300 ||
21
- x > 0x36f && x < 0x483 ||
22
- x > 0x487 && x < 0xa67c ||
23
- x > 0xa67d) && x || nil
24
- end
25
-
26
- ( self.unpack( 'U*' ).map do |x|
27
- crop_diacritics( x ) ; end.compact ) <=>
28
- ( value.unpack( 'U*' ).map do |x|
29
- crop_diacritics( x ) ; end.compact )
11
+ module Mixin
12
+ class InvalidOption < StandardError
13
+ end
14
+
15
+ module CompareString
16
+ def compare_to(value, opts = {})
17
+ if opts == :ignore_diacritics || opts.instance_of?(Hash) && opts.key?(:ignore_diacritics)
18
+ # TODO: verify composite range
19
+ def crop_diacritics(x)
20
+ (x < 0x300 || x > 0x36f && x < 0x483 || x > 0x487 && x < 0xa67c || x > 0xa67d) && x || nil
21
+ end
22
+
23
+ (unpack('U*').map do |x| crop_diacritics(x)end.compact) <=>
24
+ (value.unpack('U*').map do |x| crop_diacritics(x)end.compact)
25
+ else
26
+ self <=> value
27
+ end
28
+ end
29
+ end
30
+
31
+ module ReverseString
32
+ Fixups = [:reverse]
33
+
34
+ Aliases = { __rdoba_mixin_reverse_orig__: :reverse }
35
+
36
+ def __rdoba_mixin_reverse__(step = 1)
37
+ if (!step.is_a?(Numeric) || step < 0) && step != :byte_by_byte
38
+ raise "Invalid step value #{step.inspect}"
39
+ end
40
+
41
+ if [:byte_by_byte, String::ByteByByte].include?(step)
42
+ arr = []
43
+ each_byte do |byte|
44
+ arr << byte.chr
45
+ end
46
+ arr.reverse.join.force_encoding(encoding)
47
+ elsif step == 1
48
+ __rdoba_mixin_reverse_orig__
49
+ elsif step > 1
50
+ res = ''
51
+ offset = (size + 1) / step * step - step
52
+ (0..offset).step(step) do |shift|
53
+ res += self[offset - shift..offset - shift + 1]
54
+ end
55
+ res
56
+ end
57
+ end
58
+ end
59
+
60
+ module CaseString
61
+ Fixups = %i[upcase downcase]
62
+
63
+ Aliases = { __rdoba_mixin_upcase_orig__: :upcase, __rdoba_mixin_downcase_orig__: :downcase }
64
+
65
+ ConvertTable = {
66
+ up: {
67
+ ranges: [
68
+ { ords: [(0xE0..0xFF), (0x3B1..0x3CB), (0x430..0x44F)], change: proc { |chr, _value| chr -= 0x20 } },
69
+ { ords: [(0x3AC..0x3AC)], change: proc { |ord| ord -= 0x26 } },
70
+ { ords: [(0x3AD..0x3AF)], change: proc { |ord| ord -= 0x25 } },
71
+ { ords: [(0x3B0..0x3B0)], change: proc { |ord| ord -= 0x22 } },
72
+ {
73
+ ords: [
74
+ (0x1F00..0x1F07),
75
+ (0x1F10..0x1F17),
76
+ (0x1F20..0x1F27),
77
+ (0x1F30..0x1F37),
78
+ (0x1F40..0x1F47),
79
+ (0x1F50..0x1F57),
80
+ (0x1F60..0x1F67),
81
+ (0x1F80..0x1F87),
82
+ (0x1F90..0x1F97),
83
+ (0x1Fa0..0x1Fa7),
84
+ (0x1Fb0..0x1Fb3)
85
+ ],
86
+ change: proc { |ord| ord += 0x8 }
87
+ },
88
+ { ords: [(0x450..0x45F)], change: proc { |ord| ord -= 0x50 } },
89
+ {
90
+ ords: [
91
+ (0x100..0x1B9),
92
+ (0x1C4..0x233),
93
+ (0x460..0x481),
94
+ (0x48A..0x523),
95
+ (0x1E00..0x1E95),
96
+ (0x1EA0..0x1EFF),
97
+ (0x0A642..0xA667),
98
+ (0x0A680..0x0A697),
99
+ (0xA722..0xA7A9)
100
+ ],
101
+ change: proc { |ord| ord.odd? && (ord - 1) || ord }
102
+ }
103
+ ],
104
+ default:
105
+ proc do |ord|
106
+ [ord].pack('U').__rdoba_mixin_upcase_orig__
107
+ end
108
+ },
109
+ down: {
110
+ ranges: [
111
+ { ords: [(0xC0..0xDF), (0x391..0x3AB), (0x410..0x42F)], change: proc { |chr, _value| chr += 0x20 } },
112
+ { ords: [(0x386..0x386)], change: proc { |ord| ord += 0x26 } },
113
+ { ords: [(0x388..0x38A)], change: proc { |ord| ord += 0x25 } },
114
+ { ords: [(0x38E..0x38E)], change: proc { |ord| ord += 0x22 } },
115
+ {
116
+ ords: [
117
+ (0x1F08..0x1F0F),
118
+ (0x1F18..0x1F1F),
119
+ (0x1F28..0x1F2F),
120
+ (0x1F38..0x1F3F),
121
+ (0x1F48..0x1F4F),
122
+ (0x1F58..0x1F5F),
123
+ (0x1F68..0x1F6F),
124
+ (0x1F88..0x1F8F),
125
+ (0x1F98..0x1F9F),
126
+ (0x1Fa8..0x1FaF),
127
+ (0x1Fb8..0x1FbA)
128
+ ],
129
+ change: proc { |ord| ord -= 0x8 }
130
+ },
131
+ { ords: [(0x400..0x40F)], change: proc { |ord| ord += 0x50 } },
132
+ {
133
+ ords: [
134
+ (0x100..0x1B9),
135
+ (0x1C4..0x233),
136
+ (0x450..0x481),
137
+ (0x48A..0x523),
138
+ (0x1E00..0x1E95),
139
+ (0x1EA0..0x1EFF),
140
+ (0x0A642..0xA667),
141
+ (0x0A680..0x0A697),
142
+ (0xA722..0xA7A9)
143
+ ],
144
+ change: proc { |ord| ord.even? && (ord + 1) || ord }
145
+ }
146
+ ],
147
+ default:
148
+ proc do |ord|
149
+ [ord].pack('U').__rdoba_mixin_downcase_orig__
150
+ end
151
+ }
152
+ }
153
+
154
+ def self.change_case_char(dest, char)
155
+ ord = char.is_a?(String) ? char.ord : char.to_i
156
+ table = ConvertTable[dest]
157
+ nord =
158
+ table[:ranges].each do |range|
159
+ c =
160
+ range[:ords].each do |r|
161
+ if r.include?(ord)
162
+ break false
163
+ end
164
+ end
165
+ unless c
166
+ break range[:change].call ord
167
+ end
168
+ end
169
+
170
+ unless nord.is_a? Numeric
171
+ return table[:default].call ord
172
+ end
173
+
174
+ [nord].pack('U')
175
+ end
176
+
177
+ def self.up_char(char)
178
+ CaseString.change_case_char :up, char
179
+ end
180
+
181
+ def self.downcase_char(char)
182
+ CaseString.change_case_char :down, char
183
+ end
184
+
185
+ if RUBY_VERSION < '1.9'
186
+ alias setbyte []=
187
+
188
+ def encoding
189
+ 'UTF-8'
190
+ end
191
+
192
+ def force_encoding(*_args)
193
+ self
194
+ end
195
+
196
+ def ord
197
+ a = nil
198
+ each_byte do |b|
199
+ case (b & 0xC0)
200
+ when 0xc0
201
+ a = (b & 0x3F)
202
+ when 0x80
203
+ return (a << 6) + (b & 0x3F)
30
204
  else
31
- self <=> value ; end ; end ; end
32
-
33
- module ReverseString
34
-
35
- Fixups = [ :reverse ]
36
-
37
- Aliases = {
38
- :__rdoba_mixin_reverse_orig__ => :reverse
39
- }
40
-
41
-
42
- def __rdoba_mixin_reverse__ step = 1
43
- if ( !step.is_a?( Numeric ) || step < 0 ) && step != :byte_by_byte
44
- raise "Invalid step value #{step.inspect}" ; end
45
-
46
- if step == :byte_by_byte || step == String::ByteByByte
47
- arr = []
48
- self.each_byte do | byte |
49
- arr << byte.chr ; end
50
- arr.reverse.join.force_encoding( self.encoding )
51
- elsif step == 1
52
- __rdoba_mixin_reverse_orig__
53
- elsif step > 1
54
- res = ''
55
- offset = (self.size + 1) / step * step - step
56
- ( 0..offset ).step( step ) do | shift |
57
- res += self[ offset - shift..offset - shift + 1 ] ; end
58
- res ; end ; end ; end
59
-
60
- module CaseString
61
- Fixups = [ :upcase, :downcase ]
62
-
63
- Aliases = {
64
- :__rdoba_mixin_upcase_orig__ => :upcase,
65
- :__rdoba_mixin_downcase_orig__ => :downcase
66
- }
67
-
68
- ConvertTable = {
69
- :up => {
70
- :ranges => [ {
71
- :ords => [ (0xE0..0xFF), (0x3B1..0x3CB),
72
- (0x430..0x44F) ],
73
- :change => proc { | chr, value | chr -= 0x20 },
74
- }, {
75
- :ords => [ (0x3AC..0x3AC) ],
76
- :change => proc { | ord | ord -= 0x26 },
77
- }, {
78
- :ords => [ (0x3AD..0x3AF) ],
79
- :change => proc { | ord | ord -= 0x25 },
80
- }, {
81
- :ords => [ (0x3B0..0x3B0) ],
82
- :change => proc { | ord | ord -= 0x22 },
83
- }, {
84
- :ords => [ (0x1F00..0x1F07), (0x1F10..0x1F17),
85
- (0x1F20..0x1F27), (0x1F30..0x1F37),
86
- (0x1F40..0x1F47), (0x1F50..0x1F57),
87
- (0x1F60..0x1F67), (0x1F80..0x1F87),
88
- (0x1F90..0x1F97), (0x1Fa0..0x1Fa7),
89
- (0x1Fb0..0x1Fb3), ],
90
- :change => proc { | ord | ord += 0x8 },
91
- }, {
92
- :ords => [ (0x450..0x45F) ],
93
- :change => proc { | ord | ord -= 0x50 },
94
- }, {
95
- :ords => [ (0x100..0x1B9), (0x1C4..0x233),
96
- (0x460..0x481), (0x48A..0x523),
97
- (0x1E00..0x1E95), (0x1EA0..0x1EFF),
98
- (0x0A642..0xA667), (0x0A680..0x0A697),
99
- (0xA722..0xA7A9) ],
100
- :change => proc { | ord | ord.odd? && ( ord - 1 ) || ord },
101
- } ],
102
- :default => proc do | ord |
103
- [ ord ].pack( 'U' ).__rdoba_mixin_upcase_orig__ ; end },
104
- :down => {
105
- :ranges => [ {
106
- :ords => [ (0xC0..0xDF), (0x391..0x3AB),
107
- (0x410..0x42F) ],
108
- :change => proc { |chr, value| chr += 0x20 },
109
- }, {
110
- :ords => [ (0x386..0x386) ],
111
- :change => proc { | ord | ord += 0x26 },
112
- }, {
113
- :ords => [ (0x388..0x38A) ],
114
- :change => proc { | ord | ord += 0x25 },
115
- }, {
116
- :ords => [ (0x38E..0x38E) ],
117
- :change => proc { | ord | ord += 0x22 },
118
- }, {
119
- :ords => [ (0x1F08..0x1F0F), (0x1F18..0x1F1F),
120
- (0x1F28..0x1F2F), (0x1F38..0x1F3F),
121
- (0x1F48..0x1F4F), (0x1F58..0x1F5F),
122
- (0x1F68..0x1F6F), (0x1F88..0x1F8F),
123
- (0x1F98..0x1F9F), (0x1Fa8..0x1FaF),
124
- (0x1Fb8..0x1FbA), ],
125
- :change => proc { | ord | ord -= 0x8 },
126
- }, {
127
- :ords => [ (0x400..0x40F) ],
128
- :change => proc { | ord | ord += 0x50 },
129
- }, {
130
- :ords => [ (0x100..0x1B9), (0x1C4..0x233),
131
- (0x450..0x481), (0x48A..0x523),
132
- (0x1E00..0x1E95), (0x1EA0..0x1EFF),
133
- (0x0A642..0xA667), (0x0A680..0x0A697),
134
- (0xA722..0xA7A9) ],
135
- :change => proc { | ord | ord.even? && ( ord + 1 ) || ord },
136
- } ],
137
- :default => proc do | ord |
138
- [ ord ].pack( 'U' ).__rdoba_mixin_downcase_orig__ ; end } }
139
-
140
- def self.change_case_char dest, char
141
- ord = char.is_a?( String ) ? char.ord : char.to_i
142
- table = ConvertTable[ dest ]
143
- nord = table[ :ranges ].each do |range|
144
- c = range[ :ords ].each do |r|
145
- if r.include?( ord )
146
- break false ; end ; end
147
- if !c
148
- break range[ :change ].call ord ; end ; end
149
-
150
- if !nord.is_a? Numeric
151
- return table[ :default ].call ord ; end
152
-
153
- [ nord ].pack( 'U' ) ; end
154
-
155
- def self.up_char char
156
- CaseString.change_case_char :up, char ; end
157
-
158
- def self.downcase_char char
159
- CaseString.change_case_char :down, char ; end
160
-
161
- if RUBY_VERSION < '1.9'
162
- alias :setbyte :[]=
163
-
164
- def encoding
165
- 'UTF-8'
205
+ return b
166
206
  end
207
+ end
208
+ end
209
+ end
210
+
211
+ def __rdoba_mixin_downcase__(options = {})
212
+ __rdoba_mixin_changecase__ :down, options
213
+ end
214
+
215
+ def __rdoba_mixin_upcase__(options = {})
216
+ __rdoba_mixin_changecase__ :up, options
217
+ end
218
+
219
+ def __rdoba_mixin_changecase__(reg, options = {})
220
+ unless %i[up down].include? reg
221
+ return self
222
+ end
223
+
224
+ re = Regexp.new '[\x80-\xFF]', nil, 'n'
225
+ if options == String::FirstChar || options.include?(:first_char)
226
+ r = dup
227
+ r[0] = CaseString.change_case_char reg, ord
228
+ r
229
+ elsif dup.force_encoding('ASCII-8BIT').match re
230
+ unpack('U*').map do |chr|
231
+ CaseString.change_case_char reg, chr
232
+ end.join
233
+ elsif reg == :up
234
+ __rdoba_mixin_upcase_orig__
235
+ else
236
+ __rdoba_mixin_downcase_orig__
237
+ end
238
+ end
239
+ end
240
+
241
+ module To_hArray
242
+ def to_h(options = {})
243
+ h = {}
244
+ each do |v|
245
+ if v.is_a? Array
246
+ if h.key? v[0]
247
+ unless h[v[0]].is_a? Array
248
+ h[v[0]] = [h[v[0]]]
249
+ end
250
+
251
+ if v.size > 2
252
+ h[v[0]].concat v[1..-1]
253
+ else
254
+ h[v[0]] << v[1]
255
+ end
256
+ else
257
+ h[v[0]] = v.size > 2 && v[1..-1] || v[1]
258
+ end
259
+ elsif h.key? v
260
+ unless h[v].is_a? Array
261
+ h[v] = [h[v]]
262
+ end
263
+
264
+ h[v] << v
265
+ else
266
+ h[v] = nil
267
+ end
268
+ end
167
269
 
168
- def force_encoding(*args)
169
- self
270
+ if options[:save_unique]
271
+ h.each_pair do |_k, v|
272
+ if v.is_a? Array
273
+ v.uniq!
170
274
  end
275
+ end
276
+ end
277
+
278
+ h
279
+ end
280
+ end
281
+
282
+ module Split_byArray
283
+ #
284
+ # +split_by+ method splits the +self+ array by a condition,
285
+ # which is evaliated in a passed block, in two versions that are
286
+ # the return value. Usage:
287
+ #
288
+ # require 'rdoba'
289
+ #
290
+ # rdoba mixin: :split_by
291
+ #
292
+ # (first, second) = [0,1,2,3].split_by { |value| value % 2 == 0 }
293
+ # first # => [0,2]
294
+ # second # => [1,3]
295
+ #
296
+ def split_by
297
+ idxs = []
298
+ rejected = reject.with_index do |v, i| yield(v) && (idxs << i)end
299
+ [values_at(*idxs), rejected]
300
+ end
301
+ end
302
+
303
+ module EmptyObject
304
+ def empty?
305
+ false
306
+ end
307
+ end
308
+
309
+ module EmptyNilClass
310
+ def empty?
311
+ true
312
+ end
313
+ end
314
+ end
315
+ end
171
316
 
172
- def ord
173
- a = nil
174
- self.each_byte do |b|
175
- case ( b & 0xC0 )
176
- when 0xc0
177
- a = (b & 0x3F)
178
- when 0x80
179
- return (a << 6) + (b & 0x3F)
180
- else
181
- return b ; end ; end ; end ; end
182
-
183
- def __rdoba_mixin_downcase__ options = {}
184
- self.__rdoba_mixin_changecase__ :down, options ; end
185
-
186
- def __rdoba_mixin_upcase__ options = {}
187
- self.__rdoba_mixin_changecase__ :up, options ; end
188
-
189
- def __rdoba_mixin_changecase__ reg, options = {}
190
- if ![ :up, :down ].include? reg
191
- return self ; end
192
-
193
- re = Regexp.new '[\x80-\xFF]', nil, 'n'
194
- if options == String::FirstChar || options.include?( :first_char )
195
- r = self.dup
196
- r[0] = CaseString.change_case_char reg, self.ord
197
- r
198
- elsif self.dup.force_encoding( 'ASCII-8BIT' ).match re
199
- self.unpack('U*').map do | chr |
200
- CaseString.change_case_char reg, chr
201
- end.join
202
- elsif reg == :up
203
- self.__rdoba_mixin_upcase_orig__
204
- else
205
- self.__rdoba_mixin_downcase_orig__ ; end ; end ; end
206
-
207
- module To_hArray
208
- def to_h options = {}
209
- h = {}
210
- self.each do |v|
211
- if v.is_a? Array
212
- if h.key? v[ 0 ]
213
- if !h[ v[ 0 ] ].is_a? Array
214
- h[ v[ 0 ] ] = [ h[ v[ 0 ] ] ] ; end
215
-
216
- if v.size > 2
217
- h[ v [ 0 ] ].concat v[ 1..-1 ]
218
- else
219
- h[ v [ 0 ] ] << v[ 1 ] ; end
220
- else
221
- h[ v[ 0 ] ] = v.size > 2 && v[ 1..-1] || v[ 1 ] ; end
222
- else
223
- if h.key? v
224
- if !h[ v ].is_a? Array
225
- h[ v ] = [ h[ v ] ] ; end
226
-
227
- h[ v ] << v
228
- else
229
- h[ v ] = nil ; end ; end ; end
230
-
231
- if options[ :save_unique ]
232
- h.each_pair do |k,v|
233
- if v.is_a? Array
234
- v.uniq! ; end ; end ; end
235
-
236
- h ; end ; end
237
-
238
- module Split_byArray
239
- #
240
- # +split_by+ method splits the +self+ array by a condition,
241
- # which is evaliated in a passed block, in two versions that are
242
- # the return value. Usage:
243
- #
244
- # require 'rdoba'
245
- #
246
- # rdoba mixin: :split_by
247
- #
248
- # (first, second) = [0,1,2,3].split_by { |value| value % 2 == 0 }
249
- # first # => [0,2]
250
- # second # => [1,3]
251
- #
252
- def split_by &block
253
- idxs = []
254
- rejected = self.reject.with_index do |v, i|
255
- yield( v ) && ( idxs << i ) ; end
256
- [ self.values_at(*idxs), rejected ] ; end ; end
257
-
258
- module EmptyObject
259
- def empty?
260
- false ; end ; end
261
-
262
- module EmptyNilClass
263
- def empty?
264
- true ; end ; end ; end ; end
265
-
266
- if RUBY_VERSION >= "2.0.0"
267
- require_relative 'mixin/try'
317
+ if RUBY_VERSION >= '2.0.0'
318
+ require_relative 'mixin/try'
268
319
  else
269
- require_relative 'mixin/try_1_9_0' ; end
320
+ require_relative 'mixin/try_1_9_0'
321
+ end
270
322
 
271
323
  require_relative 'mixin/wait_if'
272
324
 
273
325
  module Rdoba
274
- def self.mixin options
275
- [ options[ :value ] ].flatten.each do |value|
276
- case value
277
- when :case
278
- Mixin::CaseString::Aliases.each do |k,v|
279
- ::String.send :alias_method, k, v ; end
280
- Mixin::CaseString::Fixups.each do |e|
281
- ::String.class_eval "def #{e}(*args);self.__rdoba_mixin_#{e}__(*args);end"
282
- end # trap NameError
283
- ::String.send :include, Mixin::CaseString
284
- when :reverse
285
- Mixin::ReverseString::Aliases.each do |k,v|
286
- ::String.send :alias_method, k, v ; end
287
- Mixin::ReverseString::Fixups.each do |e|
288
- ::String.class_eval "def #{e}(*args);self.__rdoba_mixin_#{e}__(*args);end"
289
- end # trap NameError
290
- String.send :include, Mixin::ReverseString
291
- when :compare
292
- String.send :include, Mixin::CompareString
293
- when :to_h
294
- if [].respond_to?( :to_h )
295
- m = Mixin::To_hArray.instance_method( :to_h )
296
- Array.send( :define_method, :to_h, m )
297
- else
298
- Array.send( :include, Mixin::To_hArray ) ; end
299
- when :time
300
- require_relative 'mixin/time'
301
- if File.respond_to?( :mtime )
302
- [ :mtime, :atime, :ctime ].each do |name|
303
- m = Mixin::Time.instance_method( name )
304
- ::File.send( :define_singleton_method, name, m ) ; end
305
- else
306
- ::File.send( :extend, Mixin::Time ) ; end
307
- when :wait_if
308
- Object.send :include, Mixin::Wait_ifKernel
309
- when :split_by
310
- Array.send :include, Mixin::Split_byArray
311
- when :try
312
- Object.send :include, Mixin::TryObject
313
- when :empty
314
- Object.send :include, Mixin::EmptyObject
315
- NilClass.send :include, Mixin::EmptyNilClass
316
- else
317
- raise( Mixin::InvalidOption, "Invalid rdoba-mixin options key: " +
318
- "#{value.to_s}" )
319
- end ; end ; end ; end
320
-
321
-
326
+ def self.mixin(options)
327
+ [options[:value]].flatten.each do |value|
328
+ case value
329
+ when :case
330
+ Mixin::CaseString::Aliases.each do |k, v|
331
+ ::String.send :alias_method, k, v
332
+ end
333
+ Mixin::CaseString::Fixups.each do |e|
334
+ ::String.class_eval "def #{e}(*args);self.__rdoba_mixin_#{e}__(*args);end", __FILE__, __LINE__
335
+ end
336
+ ::String.include Mixin::CaseString
337
+ when :reverse
338
+ Mixin::ReverseString::Aliases.each do |k, v|
339
+ ::String.send :alias_method, k, v
340
+ end
341
+ Mixin::ReverseString::Fixups.each do |e|
342
+ ::String.class_eval "def #{e}(*args);self.__rdoba_mixin_#{e}__(*args);end", __FILE__, __LINE__
343
+ end
344
+ String.include Mixin::ReverseString
345
+ when :compare
346
+ String.include Mixin::CompareString
347
+ when :to_h
348
+ if [].respond_to?(:to_h)
349
+ m = Mixin::To_hArray.instance_method(:to_h)
350
+ Array.send(:define_method, :to_h, m)
351
+ else
352
+ Array.include Mixin::To_hArray
353
+ end
354
+ when :time
355
+ require_relative 'mixin/time'
356
+ if File.respond_to?(:mtime)
357
+ %i[mtime atime ctime].each do |name|
358
+ m = Mixin::Time.instance_method(name)
359
+ ::File.send(:define_singleton_method, name, m)
360
+ end
361
+ else
362
+ ::File.extend Mixin::Time
363
+ end
364
+ when :wait_if
365
+ Object.include Mixin::Wait_ifKernel
366
+ when :split_by
367
+ Array.include Mixin::Split_byArray
368
+ when :try
369
+ Object.include Mixin::TryObject
370
+ when :empty
371
+ Object.include Mixin::EmptyObject
372
+ NilClass.include Mixin::EmptyNilClass
373
+ else
374
+ raise(Mixin::InvalidOption, 'Invalid rdoba-mixin options key: ' + value.to_s)
375
+ end
376
+ end
377
+ end
378
+ end