Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.ruby > #2161

Re: Simple array.each do |x| question

From 7stud -- <bbxx789_05ss@yahoo.com>
Newsgroups comp.lang.ruby
Subject Re: Simple array.each do |x| question
Date 2011-04-02 13:58 -0500
Organization Service de news de lacave.net
Message-ID <0d447c370de17e3a2a4ee56bde1114ac@ruby-forum.com> (permalink)
References <bfa8a96c7e42c61220c2d0d954eca93c@ruby-forum.com>

Show all headers | View raw


> This all sounds great but I am a little confused
> with what you exactly mean by, "Feel free to swap out
> do . . . end with { . . . }."

ruby actually has two syntaxes for blocks:

1)

['hello', 'world', 'goodbye'].each {|word| puts word.upcase}

2)

['hello', 'world', 'goodbye'].each do |word|
  puts word.upcase
end

The general practice is: use parentheses for one liners, and do-end for 
multi line blocks.

There is actually one slight difference in effect between the two 
syntaxes, but it is not worth mentioning at this point.

-- 
Posted via http://www.ruby-forum.com/.

Back to comp.lang.ruby | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Simple array.each do |x| question "Kyle X." <haebooty@yahoo.com> - 2011-03-31 17:26 -0500
  Re: Simple array.each do |x| question Roger Braun <roger@rogerbraun.net> - 2011-03-31 17:35 -0500
    Re: Simple array.each do |x| question "Kyle X." <haebooty@yahoo.com> - 2011-03-31 17:59 -0500
      Re: Simple array.each do |x| question Gunther Diemant <g.diemant@gmx.net> - 2011-03-31 18:06 -0500
        Re: Simple array.each do |x| question "Kyle X." <haebooty@yahoo.com> - 2011-03-31 18:30 -0500
        Re: Simple array.each do |x| question "Kyle X." <haebooty@yahoo.com> - 2011-04-01 14:29 -0500
          Re: Simple array.each do |x| question "Kyle X." <haebooty@yahoo.com> - 2011-04-01 15:31 -0500
          Re: Simple array.each do |x| question "Kyle X." <haebooty@yahoo.com> - 2011-04-02 01:39 -0500
            Re: Simple array.each do |x| question 7stud -- <bbxx789_05ss@yahoo.com> - 2011-04-02 13:32 -0500
  Re: Simple array.each do |x| question 7stud -- <bbxx789_05ss@yahoo.com> - 2011-04-02 13:58 -0500
    Re: Simple array.each do |x| question "Kyle X." <haebooty@yahoo.com> - 2011-04-04 13:55 -0500
  Re: Simple array.each do |x| question "Kyle X." <haebooty@yahoo.com> - 2011-04-06 00:57 -0500

csiph-web