From: Lloyd Linklater Date: 2007-06-02T23:07:41+09:00 Subject: Re: Getting the last N bytes of a string: ok, I have a question now. In the original post, he wanted to cover errors caused by undersized strings. I have been trying to grok the "zen of ruby" from posts in here and I thought that writing Ruby-ish code involves two things: 1. making it so that it reads as plain English and 2. Letting Ruby do the work for you. I could do it easily enough in Pascal, for example: s := @s[length(s) - 10]; but then we need to check for length errors as mentioned before. Here comes the question, why was my approach wrong? I am assuming that it was horrible because no one even bothered to tell me that I was being a total goober by saying this: 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'.reverse.slice(0..9).reverse I know that just having working code is not enough or we could use C# and have done with it. How do we make it readable? How do we let Ruby do the work? It seems to me that approaches like str[/(.{1,10}\z)/] are neither plain language readable nor letting Ruby do the work as it seems that the work is in the coding. Assuming that all the variations work equally well, how does one choose which is the more "ruby like" in its approach? How can I tell which approach is ugly and which is elegant? -- Posted via http://www.ruby-forum.com/.