tag:blogger.com,1999:blog-6890958153006612459.post4020380889306983739..comments2024-03-23T03:23:58.477-07:00Comments on TESTHEAD: Exercise 26: Congratulations, Take A Test!: Learn Ruby the Hard Way: PracticumMichael Larsenhttp://www.blogger.com/profile/16180074963526979074noreply@blogger.comBlogger2125tag:blogger.com,1999:blog-6890958153006612459.post-16573351390864937532012-06-15T18:31:34.042-07:002012-06-15T18:31:34.042-07:00Hi there!
I'm also a complete beginner in Ruby...Hi there!<br />I'm also a complete beginner in Ruby which I'm learning right now with Learn Ruby the Hard Way... <br />After going through the ex26 test, I wanted to see a correction and few comments on it to situate my learning compared to others.<br />Thanks for your blog, it is really nice to read!<br /><br />If I may, I think I found a glitch in your correction for the <br /><b>#Prints the first word after popping it off</b><br />section;<br /><br />According to rubydoc, <br />http://rubydoc.info/stdlib/core/1.9.3/Array:pop<br />Array#pop() removes the <i>last</i> element from an array and return it. If a number n is given into the pop(n), it return an array with the <i>n</i> last numbers of the original array.<br /><br />So I think using <i>popping</i> in the comment is part of a correction to do, giving a false hint on the solution;<br />According to an exercice before ex25.rb, I did the solution that way :<br /><br />def puts_first_word(words)<br /> word = words.shift()<br /> puts word<br />end<br /><br />Using <b>shift()</b>, is the exact same thing as pop(), but for the first element instead of the last;<br />http://rubydoc.info/stdlib/core/1.9.3/Array:shift<br />meaning array.shift() returns the first element, and array.shift(n) returns the <i>n</i> first elements.<br /><br />Hope this is right, and that I helped :)<br /><br />JoJonathanhttp://jypepin.tumblr.comnoreply@blogger.comtag:blogger.com,1999:blog-6890958153006612459.post-32838603058727881842011-12-23T02:56:01.565-08:002011-12-23T02:56:01.565-08:00Hello, I'm learning programming for the first ...Hello, I'm learning programming for the first time with learncodethehardway (and finding your blog very interesting as an accompaniment)... so I may be completely wrong, but I think your problem at the end is due to writing pop(1) instead of pop()<br /><br />from http://railsapi.com/doc/rails-v3.0.8rc1_ruby-v1.9.2/<br />ary.pop → obj or nil ary.pop(n) → new_ary<br /><br />Removes the last element from self and returns it, or nil if the array is empty.<br /><br />If a number n is given, returns an array of the last n elements (or less) just like array.slice!(-n, n) does.<br /><br /> a = [ "a", "b", "c", "d" ]<br /> a.pop #=> "d"<br /> a.pop(2) #=> ["b", "c"]<br /> a #=> ["a"]<br /><br />EmilyAnonymousnoreply@blogger.com