Class: SymbolW
Constant Summary
collapse
- FIX_ARGS =
lambda do |elm|
rtn = elm
if elm.kind_of? Symbol
rtn = elm.to_s
elsif elm.kind_of? SymbolW
rtn = elm.to_s
end
rtn
end
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Value
#!=, #==, #ensure_valid, #freeze, freeze_raise?, ignore_on_freeze, #initialize, #inspect, #prim_value, raise_on_freeze, #replace, #to_s, #unwrap, #val, #val=, #~
Constructor Details
This class inherits a constructor from Value
Class Method Details
.bestow_string_mutate_method(meth_def_name, meth_call_name) ⇒ Object
236
237
238
239
240
241
242
243
|
# File 'lib/primitive_wrapper.rb', line 236
def self.bestow_string_mutate_method(meth_def_name, meth_call_name)
define_method meth_def_name do |*args, &block|
prms = args.blockify_elements &FIX_ARGS
str = @value.to_s
str.send(meth_call_name, *prms, &block)
@value = str.to_sym
end
end
|
.bestow_string_mutate_methods(meths) ⇒ Object
287
288
289
290
291
|
# File 'lib/primitive_wrapper.rb', line 287
def self.bestow_string_mutate_methods(meths)
meths.each do |meth|
bestow_string_mutate_method(meth, meth)
end
end
|
.bestow_string_non_mutate_method(meth_def_name, meth_call_name, return_type = SymbolW) ⇒ Object
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
|
# File 'lib/primitive_wrapper.rb', line 245
def self.bestow_string_non_mutate_method(meth_def_name, meth_call_name, return_type = SymbolW)
if return_type==Symbol
define_method meth_def_name do |*args, &block|
prms = args.blockify_elements &FIX_ARGS
@value.to_s.send(meth_call_name, *prms, &block).to_sym
end
elsif return_type==String
define_method meth_def_name do |*args, &block|
prms = args.blockify_elements &FIX_ARGS
@value.to_s.send(meth_call_name, *prms, &block).to_s
end
elsif return_type==SymbolW
define_method meth_def_name do |*args, &block|
prms = args.blockify_elements &FIX_ARGS
SymbolW.new @value.to_s.send(meth_call_name, *prms, &block).to_s.to_sym
end
else
define_method meth_def_name do |*args, &block|
prms = args.blockify_elements &FIX_ARGS
@value.to_s.send(meth_call_name, *prms, &block)
end
end
end
|
.bestow_string_non_mutate_methods(meths, return_type = SymbolW) ⇒ Object
293
294
295
296
297
|
# File 'lib/primitive_wrapper.rb', line 293
def self.bestow_string_non_mutate_methods(meths, return_type = SymbolW)
meths.each do |meth|
bestow_string_non_mutate_method(meth, meth, return_type)
end
end
|
.bestow_symbol_method(meth_def_name, meth_call_name, mutate_self = false) ⇒ Object
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
|
# File 'lib/primitive_wrapper.rb', line 269
def self.bestow_symbol_method(meth_def_name, meth_call_name, mutate_self=false)
if mutate_self
define_method meth_def_name do |*args, &block|
margs = args.blockify_elements { |t| t.prim_value }
tval = @value.send(meth_call_name, *margs, &block)
ensure_valid(tval, "symbol mutate method not valid")
@value = tval
return self
end
else
define_method meth_def_name do |*args, &block|
margs = args.blockify_elements { |t| t.prim_value }
rtn = @value.send(meth_call_name, *margs, &block)
return rtn
end
end
end
|
.bestow_symbol_methods(meths, mutate_self = false) ⇒ Object
299
300
301
302
303
304
305
306
307
|
# File 'lib/primitive_wrapper.rb', line 299
def self.bestow_symbol_methods(meths, mutate_self=false)
meths.each do |meth|
dmeth=meth
if mutate_self
dmeth = (meth.to_s + '!').to_sym
end
bestow_symbol_method(dmeth, meth, mutate_self)
end
end
|
Instance Method Details
#include?(pat) ⇒ Boolean
why did I redefine this? don’t remember … investigate later
326
327
328
|
# File 'lib/primitive_wrapper.rb', line 326
def include? pat
self.to_s.include? pat.to_s
end
|
334
335
336
|
# File 'lib/primitive_wrapper.rb', line 334
def to_str
@value.to_s
end
|
331
332
333
|
# File 'lib/primitive_wrapper.rb', line 331
def to_sym
@value
end
|
#valid_type(prm) ⇒ Object
220
221
222
223
224
|
# File 'lib/primitive_wrapper.rb', line 220
def valid_type(prm)
return true if prm.kind_of? Symbol
return true if prm.kind_of? SymbolW
false
end
|