Class | String |
In: |
lib/more/facets/random.rb
lib/more/facets/succ.rb lib/more/facets/tuple.rb lib/more/facets/date.rb |
Parent: | Object |
Conveniently turn a string into a tuple.
succ | -> | succ1 |
Parse data from string.
# File lib/more/facets/date.rb, line 390 390: def to_date 391: #::Date::civil(*ParseDate.parsedate(self)[0..2]) 392: ::Date.new(*::Date._parse(self, false).values_at(:year, :mon, :mday)) 393: end
Translates a string in the form on a set of numerical and/or alphanumerical characters separated by non-word characters (eg \W+) into a Tuple. The values of the tuple will be converted to integers if they are purely numerical.
'1.2.3a'.to_t #=> [1,2,"3a"]
It you would like to control the interpretation of each value as it is added to the tuple you can supply a block.
'1.2.3a'.to_t { |v| v.upcase } #=> ["1","2","3A"]
This method calls Tuple.cast_from_string.
# File lib/more/facets/tuple.rb, line 309 309: def to_t( &yld ) 310: Tuple.cast_from_string( self, &yld ) 311: end