Hi,
Am Freitag, 15. Jun 2007, 23:24:29 +0900 schrieb John Joyce:
Obey at least some conventions.
class String
def shift
slice! 0, 1 if any?
end
alias lchop shift
end
Bertram
So sweet about it. What conventions do you refer to?
I said you could add to a class, I didn't do it.
I also was just trying to keep it clear.
String#slice is not well documented in rdoc. ri only gives the
formats and result types.
----------------------------------------------------------- String#slice
str[fixnum] => fixnum or nil
str[fixnum, fixnum] => new_str or nil
str[range] => new_str or nil
str[regexp] => new_str or nil
str[regexp, fixnum] => new_str or nil
str[other_str] => new_str or nil
str.slice(fixnum) => fixnum or nil
str.slice(fixnum, fixnum) => new_str or nil
str.slice(range) => new_str or nil
str.slice(regexp) => new_str or nil
Not the most clear stuff in the world for everyone.
especially this:
str.slice(fixnum, fixnum) => new_str or nil
Uh, what should those fixnums be?
Sure we could sit around and try it in irb, but better descriptions
would be better for rdoc and for everyone.
shift is a pretty poor naming btw. Makes more sense if you are
dealing with an array. Ruby's strings are not an arrays.
You missed the OP's goal. You returned the first character.
how about:
# Takes a fixnum argument. Returns a new string by removing (or
nibbling) the 'fixnum' number of bytes from the string
class String
def nibble(fixnum)
range_end = self.length - 1
slice(fixnum..range_end)
end
end