Peña, Botp
4/27/2007 10:55:00 AM
On Behalf Of Firstname Secondname:
# Exactly like that :)
Ah, do not forget, in ruby land, you can be flexible :)
C:\family\ruby>cat test.rb
class String
alias old_split split
def split arg1=' ', *args
case arg1
when Integer
self.scan(/.{1,#{arg1}}/)
else
old_split arg1, *args
end #case
end #def
end #class
p "this is a test string. okay?".split
p "this is a test string. okay?".split(/i/)
p "this is a test string. okay?".split(3)
C:\family\ruby>ruby test.rb
["this", "is", "a", "test", "string.", "okay?"]
["th", "s ", "s a test str", "ng. okay?"]
["thi", "s i", "s a", " te", "st ", "str", "ing", ". o", "kay", "?"]
Is that ok?
kind regards -botp