From: Bravo Man Date: 2012-02-09T01:36:24+09:00 Subject: A better way implement "it" the ruby way Hi, I come from the world of other programming languages and in the process of learning Ruby I am trying to implement a few algorithms. It would be great if you could assist me with proposal for implementing it in a more "ruby" way tham directly following the pattern from "java" for example. I would like to convert integers to strings where the strings are of the form XXX. X is a digit from 0 to 9 or a letter from A to Z. So 11 gets converted to 00B. 37 is 010. And 46656 gets converted to ZZZ. An example for the algorithm is: public String generateKey(int number) { StringBuilder builder = new StringBuilder(); int mod = number % 36; int k = number; do { appendSymbol(mod, builder); k = k / 36; mod = k % 36; } while (k != 0); if (builder.length() < 3) appendSymbol(mod, builder); if (number < 36) builder.append("0"); return builder.reverse().toString(); } private char convertToLetter(int start) { int number = start - 10 + 'A'; return (char) number; } private void appendSymbol(int i, StringBuilder builder) { if (i < 10) builder.append(Integer.toString(i)); else builder.append(convertToLetter(i)); } I am sure there are plenty of ways to implement this in Ruby more clearly in a number of lines. It would be great if you could share your ideas for the implementation. -- Posted via http://www.ruby-forum.com/.