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
1536 1537 1538 |
# File 'lib/alib-0.5.1/util.rb', line 1536 def bool_cast arg arg ? true : false end |
#float_cast(arg) ⇒ Object
1533 1534 1535 |
# File 'lib/alib-0.5.1/util.rb', line 1533 def float_cast arg Float arg end |
#float_list(*list) ⇒ Object
–}}}
1517 1518 1519 1520 1521 |
# File 'lib/alib-0.5.1/util.rb', line 1517 def float_list *list #--{{{ list.flatten.compact.map{|f| Float f} #--}}} end |
#int_cast(arg) ⇒ Object
1530 1531 1532 |
# File 'lib/alib-0.5.1/util.rb', line 1530 def int_cast arg Integer arg.to_s end |
#int_list(*list) ⇒ Object
1512 1513 1514 1515 1516 |
# File 'lib/alib-0.5.1/util.rb', line 1512 def int_list *list #--{{{ list.flatten.compact.map{|i| Util.atoi i} #--}}} end |
#pathname_cast(arg, opts = {}) ⇒ Object
1559 1560 1561 1562 1563 |
# File 'lib/alib-0.5.1/util.rb', line 1559 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
1556 1557 1558 |
# File 'lib/alib-0.5.1/util.rb', line 1556 def re_cast arg Regexp === arg ? arg : %r/#{ arg }/ end |
#string_cast(arg) ⇒ Object
–}}}
1527 1528 1529 |
# File 'lib/alib-0.5.1/util.rb', line 1527 def string_cast arg arg.to_s end |
#string_list(*list) ⇒ Object
–}}}
1522 1523 1524 1525 1526 |
# File 'lib/alib-0.5.1/util.rb', line 1522 def string_list *list #--{{{ list.flatten.compact.map{|s| String s} #--}}} end |