From: Kyle on 15 Nov 2009 12:13 [Note: parts of this message were removed to make it a legal post.] It's the lazy execution boolean or operator x1 = nil x2 = [1,2,3] x3 = [4,5,6] a = x1 || x2.push(4, 5) b = x3 || x2.push(6, 7) # assignment operator version often used to initialize a variable if it doesn't already have a value @var ||= 'something' @var ||= 'whatevs' after wards: a == x2 == [1, 2, 3, 4, 5] b == x3 == [4, 5, 6] @var == 'something' On Sunday November 15 2009 7:59:31 am duxieweb wrote: > sorry just was learning ruby so have some low level questions, :) > > in this statement: > > 1.upto(10) do |c| print c," " end > > what's the usage of "| ... |" in ruby? can't easily understand. > > Thanks.
From: Kyle on 15 Nov 2009 12:16 [Note: parts of this message were removed to make it a legal post.] Sorry I hit send on the previous message before I finished -- plus I suppose "lazy" evaluation was a bad term for it. Basically, the right side of the operator isn't evaluated if the left side expression is true. && is simillar in that the right hand side isn't evaluated if the left side is false. On Sunday November 15 2009 7:59:31 am duxieweb wrote: > sorry just was learning ruby so have some low level questions, :) > > in this statement: > > 1.upto(10) do |c| print c," " end > > what's the usage of "| ... |" in ruby? can't easily understand. > > Thanks.
From: Kyle on 15 Nov 2009 12:20 [Note: parts of this message were removed to make it a legal post.] Oh lawd i'm a total jackass for not realizing there was more to the e-mail. Disregard the previous nonsense. | | is used to indicate a block variable. Ya gotta read the pickaxe book or another ruby guide for more on what that means: http://www.ruby-doc.org/docs/ProgrammingRuby/ On Sunday November 15 2009 7:59:31 am duxieweb wrote: > sorry just was learning ruby so have some low level questions, :) > > in this statement: > > 1.upto(10) do |c| print c," " end > > what's the usage of "| ... |" in ruby? can't easily understand. > > Thanks.
From: Steve Wilhelm on 15 Nov 2009 22:17 Block syntax is also clearly explained in "The Ruby Programming Language" by Flanagan & Matsumoto in section 5.4.1. Kyle wrote: > Oh lawd i'm a total jackass for not realizing there was more to the > e-mail. > Disregard the previous nonsense. | | is used to indicate a block > variable. Ya > gotta read the pickaxe book or another ruby guide for more on what that > means: > > http://www.ruby-doc.org/docs/ProgrammingRuby/ -- Posted via http://www.ruby-forum.com/.
From: duxieweb on 16 Nov 2009 01:37 2009/11/16 Steve Wilhelm <steve(a)studio831.com>: > Block syntax is also clearly explained in "The Ruby Programming > Language" by Flanagan & Matsumoto in section 5.4.1. > Thanks all. I was reading O'Reilly Learning Ruby, is this a recommended book?
First
|
Prev
|
Next
|
Last
Pages: 1 2 3 Prev: bsearch.rb Next: Newbie question: Defining a numeric type |