On 7/25/07, LeonB <leon / tim-online.nl> wrote:
> Pfff... Sorry for the second post. I couldn't find the first one on
> Google groups.
> I tried changing the self object. But I wasn't allowed to do it. I got
> an error message when I did that:
> "Can't change the value of self"
>
> So I changed it to:
>
> class String
>         def rtrim(character)
>
>                 ret = self
>                 if self[-1, 1] == character.to_s
>                         ret = self[0, self.length - 1]
>                 end
>                 return ret
>         end
>
>         def ltrim(character)
>                 if self[0, 1] == character.to_s
>                         ret = self[1, self.length]
>                 end
>                 return ret
>         end
> end
>
> This works. But I would rather see the first object changed. Is this
> possible?

Leon, look at String#slice!

Todd