Mega Code Archive

 
Categories / Ruby / String
 

Pops last character off self and returns it, changing self

class String   def pop     return nil if self.empty?     item=self[-1]     self.chop!     return nil if item.nil?     item.chr   end end a = "this is a test" puts a.pop