leonb
1
I created this function:
class String
def rtrim(character)
if self[-1, 1] == character.to_s
self[0, self.length - 1]
end
return self
end
def ltrim(character)
if self[0, 1] == character.to_s
self[1, self.length]
end
return self
end
end
Is this ok? Am I not duplicating any built-in ruby functions? Does
anyone see any possible problems with these functions?
Thanks in advance!
leonb
2
On 7/24/07, LeonB [email protected] wrote:
def ltrim(character)
if self[0, 1] == character.to_s
self[1, self.length]
end
return self
end
end
I’m not sure this does what you want it to. The object referenced by
self has not changed because the [] method does not alter the String.
Todd
leonb
3
Hi,
At Wed, 25 Jul 2007 07:55:04 +0900,
LeonB wrote in [ruby-talk:261630]:
Am I not duplicating any built-in ruby functions?
Perhaps. See String#rstrip and #lstrip.
leonb
4
On 7/26/07, Trans [email protected] wrote:
but there is no reverse or left chomp --wish there were! And it does
not support regexp. Maybe worth an RCR.
Well there is, it is just sooo expensive
James knows what I mean.
cheers
Robert
leonb
5
Trans wrote:
On Jul 24, 3:55 pm, LeonB [email protected] wrote:
Thanks in advance!
#chomp!
but there is no reverse or left chomp --wish there were! And it does
not support regexp. Maybe worth an RCR.
T.
Thanks! To bad for the missing left-chomp
leonb
6
On Jul 24, 3:55 pm, LeonB [email protected] wrote:
Thanks in advance!
#chomp!
but there is no reverse or left chomp --wish there were! And it does
not support regexp. Maybe worth an RCR.
T.