Mega Code Archive

 
Categories / Ruby / String
 

Pushes first character of provided string onto end of self

class String   def push(other)     newself = self + other.to_s.dup.shift.to_s     self.replace(newself)   end   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.push "another")