Prev: Ruby 1.9.1-p429
Next: Symbols vs. variable
From: Abder-rahman Ali on 11 Jul 2010 16:22 Thanks a lot for your clarification. Maybe what confused me a bit is that I forgot that "close" is a variable and thought it was a method in Ruby. Now I think it is more clear. -- Posted via http://www.ruby-forum.com/.
From: Abder-Rahman Ali on 13 Jul 2010 09:26 Colin Bartlett wrote: > On Sun, Jul 11, 2010 at 5:26 PM, Abder-rahman Ali < > abder.rahman.ali(a)gmail.com> wrote: > >> Hi, >> >> Regarding this part: >> >> sentence[open..close] = '' if close >> >> You explained what it means, but I just want to ask, what is ---> if >> close? >> > You can modify a statment with "if" or "unless". > A short *almost* (but not quite) accurate statement is that it is a > shorthand way of writing: > > if close > sentence[open..close] = '' > end > > # or > > if close then > sentence[open..close] = '' > end > > There's a fuller explanation here: > http://ruby-doc.org/docs/ProgrammingRuby/html/tut_expressions.html > at "If and Unless Modifiers" > > You can also use "while" and "until" as statement modifiers(see Loops > further down that page), but there is, as Programming Ruby says, a > "wrinkle": > "There's one wrinkle when while and until are used as statement > modifiers. > If the statement they are modifying is a begin/end block, the code in > the > block will always execute at least one time, regardless of the value of > the > boolean expression." I see it worked even when changing this part: close = sentence.index(')', open) To: close = sentence.index(')') What was the purpose of "open" as a second argument then? Thanks. -- Posted via http://www.ruby-forum.com/.
From: Peter Hickman on 13 Jul 2010 09:30 On 13 July 2010 14:26, Abder-Rahman Ali <abder.rahman.ali(a)gmail.com> wrote: > What was the purpose of "open" as a second argument then? RTFM http://www.ruby-doc.org/core/classes/String.html
From: Abder-Rahman Ali on 13 Jul 2010 10:21
Peter Hickman wrote: > On 13 July 2010 14:26, Abder-Rahman Ali <abder.rahman.ali(a)gmail.com> > wrote: >> What was the purpose of "open" as a second argument then? > > > RTFM http://www.ruby-doc.org/core/classes/String.html I saw it is a range? Like in the documentation: a = "hello there" a[1,3] #=> "ell" But, in the example I provided close = sentence.index(')', open) I get ) ( Still not getting the purpose. Thanks. -- Posted via http://www.ruby-forum.com/. |