From: Sean O'Dell Date: 2002-03-23T08:08:47+09:00 Subject: Re: Sub-String "Mike Stok" wrote in message news:slrna9n4h8.v47.mike@ratdog.stok.co.uk... > In article , > Sean O'Dell wrote: > > > Yeah, that worked great, thank you. Where did you learn to do that? I > > bought three Ruby books and even now that I know how to do that, I can't > > find reference to that anywhere. I must be missing something. > > First of all I fire up irb and just try a couple of likely names and > argument lists, many times that "just works" as I get more used to Ruby. > irb is a quick way to learn by doing... > > If that fails, then I look in my copy of Programming Ruby at the Built-In > Classes and Methods section if I can, failing that (e.g. when at work) I > go on line - in this case to http://www.rubycentral.com/book/builtins.html > - and look for a likely method name. Once I have read the description > I try it in irb to see if I have understood what I read. > > That's what I did this time, if that hadn't worked then I would have searched > on google for > > ruby substr > > and found something like > > www.zenspider.com/Languages/Ruby/Cookbook/Strings/AccessingSubstrings.html I have that same book, but I didn't glean the information about ranges pulling out the remainder of the string. I read that negatives work backwards from the end, but I thought a -1 would cause the range to stop before the last character in the string, excluding it, and so 0 would indicate the very end of the string, except 0 just means 0 length. I'm still not entirely sure why -1 is means the very end of the string. I guess -1 means the last character (one back from the very end), and since '..' was used in the range, it means include the last character indicated, so the whole expression means include everything up to and including the last character, AKA the whole string. I guess I'm not used to using ranges...it'll sink in my head eventually. Sean