aboutsummaryrefslogblamecommitdiffstats
path: root/activesupport/lib/active_support/core_ext/string/access.rb
blob: 23aaee9c4338ce73fef38a98622558a234d7690f (plain) (tree)
1
2
3
4
5
6
7
8
9
10
                                  
 
            


                  
 


                      
 


                     
 






                       
       
     
 






                       

       
   
require 'active_support/multibyte'

class String
  def at(position)
    self[position]
  end

  def from(position)
    self[position..-1]
  end

  def to(position)
    self[0..position]
  end

  def first(limit = 1)
    if limit == 0
      ''
    elsif limit >= size
      self
    else
      to(limit - 1)
    end
  end

  def last(limit = 1)
    if limit == 0
      ''
    elsif limit >= size
      self
    else
      from(-limit)
    end
  end
end