Mega Code Archive

 
Categories / Ruby / String
 

Adds last character of provided string to front of self

class String   def pop     return nil if self.empty?     item=self[-1]     self.chop!     return nil if item.nil?     item.chr   end   def unshift(other)     newself = other.to_s.dup.pop.to_s + self     self.replace(newself)   end end a = "this is a test" puts (a.unshift "asfd")