From: Joel VanderWerf Date: 2006-01-31T15:13:53+09:00 Subject: Re: Array prepending nil object Serdar K脹l脹巽 wrote: > I'm going through Brian Schr旦der's tutorial and hit a small snag. The > code is (on page 16): > > print 'Array as stack: ' > stack = Array.new() > stack.push('a') > stack.push('b') > stack.push('c') > print stack.pop until stack.empty? > > The display that I'm getting is: > Array as stack: cbanil > > So somehow nil is creeping it's way into my array but I'm not sure > how. Any ideas? The nil is just the return value of the last expression, not part of the output of the print calls. You can see it more clearly in irb: irb(main):001:0> print 'Array as stack: ' Array as stack: => nil irb(main):002:0> stack = Array.new() => [] irb(main):003:0> stack.push('a') => ["a"] irb(main):004:0> stack.push('b') => ["a", "b"] irb(main):005:0> stack.push('c') => ["a", "b", "c"] irb(main):006:0> print stack.pop until stack.empty? cba=> nil The printed output shows up on the left of the =>. -- vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407