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, #to_wrapper, #type, #type_of?, #unwrap, #val, #val=, #wrapped?, #~
Constructor Details
This class inherits a constructor from Value
Class Method Details
.bestow_string_mutate_method(meth_def_name, meth_call_name) ⇒ Object
340
341
342
343
344
345
346
347
|
# File 'lib/primitive_wrapper.rb', line 340
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
391
392
393
394
395
|
# File 'lib/primitive_wrapper.rb', line 391
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
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
|
# File 'lib/primitive_wrapper.rb', line 349
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
397
398
399
400
401
|
# File 'lib/primitive_wrapper.rb', line 397
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
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
|
# File 'lib/primitive_wrapper.rb', line 373
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
403
404
405
406
407
408
409
410
411
|
# File 'lib/primitive_wrapper.rb', line 403
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
430
431
432
|
# File 'lib/primitive_wrapper.rb', line 430
def include? pat
self.to_s.include? pat.to_s
end
|
438
439
440
|
# File 'lib/primitive_wrapper.rb', line 438
def to_str
@value.to_s
end
|
435
436
437
|
# File 'lib/primitive_wrapper.rb', line 435
def to_sym
@value
end
|
#valid_type(prm) ⇒ Object
324
325
326
327
328
|
# File 'lib/primitive_wrapper.rb', line 324
def valid_type(prm)
return true if prm.kind_of? Symbol
return true if prm.kind_of? SymbolW
false
end
|