Module: ALib::Util::Casting
Overview
casting methods
Instance Method Summary collapse
- #bool_cast(arg) ⇒ Object
- #float_cast(arg) ⇒ Object
-
#float_list(*list) ⇒ Object
–}}}.
- #int_cast(arg) ⇒ Object
- #int_list(*list) ⇒ Object
- #pathname_cast(arg, opts = {}) ⇒ Object
- #re_cast(arg) ⇒ Object
-
#string_cast(arg) ⇒ Object
–}}}.
-
#string_list(*list) ⇒ Object
–}}}.
Methods included from Exporter
Instance Method Details
#bool_cast(arg) ⇒ Object
1528 1529 1530 |
# File 'lib/alib-0.5.0/util.rb', line 1528 def bool_cast arg arg ? true : false end |
#float_cast(arg) ⇒ Object
1525 1526 1527 |
# File 'lib/alib-0.5.0/util.rb', line 1525 def float_cast arg Float arg end |
#float_list(*list) ⇒ Object
–}}}
1509 1510 1511 1512 1513 |
# File 'lib/alib-0.5.0/util.rb', line 1509 def float_list *list #--{{{ list.flatten.compact.map{|f| Float f} #--}}} end |
#int_cast(arg) ⇒ Object
1522 1523 1524 |
# File 'lib/alib-0.5.0/util.rb', line 1522 def int_cast arg Integer arg.to_s end |
#int_list(*list) ⇒ Object
1504 1505 1506 1507 1508 |
# File 'lib/alib-0.5.0/util.rb', line 1504 def int_list *list #--{{{ list.flatten.compact.map{|i| Util.atoi i} #--}}} end |
#pathname_cast(arg, opts = {}) ⇒ Object
1551 1552 1553 1554 1555 |
# File 'lib/alib-0.5.0/util.rb', line 1551 def pathname_cast arg, opts = {} = opts['expand'] || opts[:expand] pn = (Pathname === arg ? arg : Pathname.new(arg.to_s)) ? pn. : pn end |
#re_cast(arg) ⇒ Object
1548 1549 1550 |
# File 'lib/alib-0.5.0/util.rb', line 1548 def re_cast arg Regexp === arg ? arg : %r/#{ arg }/ end |
#string_cast(arg) ⇒ Object
–}}}
1519 1520 1521 |
# File 'lib/alib-0.5.0/util.rb', line 1519 def string_cast arg arg.to_s end |
#string_list(*list) ⇒ Object
–}}}
1514 1515 1516 1517 1518 |
# File 'lib/alib-0.5.0/util.rb', line 1514 def string_list *list #--{{{ list.flatten.compact.map{|s| String s} #--}}} end |