From: Jeff Wood Date: 2005-08-18T22:30:09+09:00 Subject: Re: Newbie question --------------000306060505030509080507 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Jeff Wood wrote: > Lothar Scholz wrote: > >> Hello len, >> >> l> Is there some difference in the code I'm not seeing or is one better >> l> than the other: >> >> l> languages = ['English', 'German', 'Ruby'] >> >> l> languages.each do |lang| >> l> puts 'I love ' + lang + '!' >> l> puts 'Don\'t you?' >> l> end >> >> l> languages.each { |lang| >> l> puts 'I love ' + lang + '!' >> l> puts "Don't you?"} >> >> >> No both are the same, the one liner >> >> languages.each { |lang| puts "I love #{lang}!\nDon't you?" } >> >> is also doing the same and a little bit more rubyish >> >> >> > Both are acceptable, but it is common convention that you use {} for > one-liners and use do end for multi-line blocks. > > j. > Oh, and there is quite a difference in the evaluation of both within the interpreter due to order of operations issues. There's a good write up of this in the PickAxe (The standard Ruby reference material ( book ) Programming Ruby by Dave Thomas) j. --------------000306060505030509080507--