Mega Code Archive

 
Categories / Ruby / String
 

Removes first character from self and returns it, changing self

class String   def shift     return nil if self.empty?     item=self[0]     self.sub!(/^./,"")     return nil if item.nil?     item.chr   end end a = "this is a test" puts a.shift