Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

[REBOL] Re: What's wrong with Ruby

From: w_a_x_man::yahoo at: 27-Mar-2007 13:31

--- Paavo Nevalainen <Paavo.Nevalainen-saunalahti.fi> wrote:
> I taught students some basic principles of programming, > including concepts of algorithm, function, and such. One > result of the course was list of small programing tasks > implemented in various languages. An example was > to pseudonymize one's name with these rules: > 1) invert all words > 2) initial letters to capitals > 3) sort the shortest ones first > > As you see, Perl equivalent is not done. You can add it > and post to me, if you wish. The codes do not have exactly > same behaviour when input is completely odd (more than > one capital letter per word, too short words and such). > > > # Ruby: ----------------------------------------- > > def pseudonymize(name) > names= Array.[] > name.reverse.downcase.each(' ') { > |s| names << s.chomp(" ").capitalize > } > names.sort {|x,y| x.length <=> y.length} > names= names.reverse > > out= "" > names.each {|x| out << x << " "} > out.chomp(" ") > end > > p pseudonymize("Abu Baba Imaam")
def pseudonymize(name) name.split.map{|s| s.reverse.capitalize}. sort_by{|s| s.size}.join(' ') end puts pseudonymize( "Veronica von Wassenshaft" ) ____________________________________________________________________________________ Don't get soaked. Take a quick peek at the forecast with the Yahoo! Search weather shortcut. http://tools.search.yahoo.com/shortcuts/#loc_weather