Module: Subroutine::TypeCaster
- Defined in:
- lib/subroutine/type_caster.rb
Class Method Summary collapse
Class Method Details
.cast(value, type, *args) ⇒ Object
23 24 25 26 27 28 |
# File 'lib/subroutine/type_caster.rb', line 23 def cast(value, type, *args) return value if value.nil? || type.nil? caster = casters[type] caster ? caster.call(value, *args) : value end |
.casters ⇒ Object
11 12 13 |
# File 'lib/subroutine/type_caster.rb', line 11 def casters @casters ||= {} end |
.register(*names, &block) ⇒ Object
16 17 18 19 20 |
# File 'lib/subroutine/type_caster.rb', line 16 def register(*names, &block) names.each do |n| casters[n] = block end end |