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.

Methods

succ   to_date   to_datetime   to_t  

Included Modules

Random

External Aliases

succ -> succ1

Public Instance methods

Allows succ to take n step increments.

  "abc".succ      #=> "abd"
  "abc".succ(4)   #=> "abg"
  "abc".succ(24)  #=> "aca"

CREDIT: Trans

[Source]

    # File lib/more/facets/succ.rb, line 37
37:   def succ(n=1)
38:     s = self
39:     n.times { s = s.succ1 }
40:     s
41:   end

Parse data from string.

[Source]

     # 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

Convert string to DateTime.

[Source]

     # File lib/more/facets/date.rb, line 384
384:   def to_datetime
385:     date = ::Date._parse(self, false).values_at(:year, :mon, :mday, :hour, :min, :sec).map { |arg| arg || 0 }
386:     ::DateTime.civil(*date)
387:   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.

[Source]

     # File lib/more/facets/tuple.rb, line 309
309:   def to_t( &yld )
310:     Tuple.cast_from_string( self, &yld )
311:   end

[Validate]