From: sl4m Date: 2010-04-01T02:27:54+09:00 Subject: Re: Ruby Koans: will this method ever return :empty? --001485eba2ccd2f59e04831c10fb Content-Type: text/plain; charset=ISO-8859-1 Yes it's true, you're suppose to fix the code and/or test, but only if it has a '__' or a comment indicating to fix something. In this case, however, it's asking what the method will return if the method was called with and without arguments. Here's the test: class MessageCatcher def add_a_payload(*args) return :empty unless args args end end def test_sending_a_message_with_arguments mc = MessageCatcher.new assert_equal __, mc.add_a_payload assert_equal __, mc.send(:add_a_payload) assert_equal __, mc.add_a_payload(3, 4, nil, 6) assert_equal __, mc.send(:add_a_payload, 3, 4, nil, 6) end The return statement will never return :empty in the asserts. This is what confused me. I wanted to know when the method will ever return :empty. The test doesn't test that...because it will never return it ;-) skim On Wed, Mar 31, 2010 at 09:07, Gennady Bystritsky < Gennady.Bystritsky@quest.com> wrote: > > On Mar 31, 2010, at 8:57 AM, Gennady Bystritsky wrote: > > > > > On Mar 31, 2010, at 8:36 AM, sl4m wrote: > > > >> Thanks guys! It looks like there's a mistake in the koans then. I'll > >> report it to the author. I ran this piece of code over and over on irb, > but > >> could not figure it out. > > > > Wasn't that the idea behind "koans"? I haven't heard about them until > your post, however according to > http://brandon.dimcheff.com/2009/02/05/how-to-learn-ruby.html: > > Darn, looks like ":" becomes the part of URL when you click the above link. > Try just this: > http://brandon.dimcheff.com/2009/02/05/how-to-learn-ruby.html > > > > > "... The Koans are essentially a series of failing test cases that you > need to figure out how to fix in order to move on to the next step." > > > > From that, my understanding is that a user is supposed to find problems > in "koans" and fix them. You found one, good going ;-) > > > > Regards, > > Gennady. > > > >> > >> > >> Cheers, > >> skim > >> > >> On Wed, Mar 31, 2010 at 05:23, Aldric Giacomoni > wrote: > >> > >>> Aldric Giacomoni wrote: > >>>> Steve Kim wrote: > >>> > >>>>> Is it possible to have this method return :empty? > >>> > >>>> > >>>> class MessageCatcher > >>>> def add_a_payload *args > >>>> args.empty? :empty : args > >>>> end > >>>> end > >>>> > >>>> args.empty? [:empty] : args > >>>> > >>> > >>> I'd appreciate it if no one mentioned that I forgot the '?' twice! I am > >>> so ashamed. > >>> > >>> args.empty? ? :empty : args > >>> args.empty? ? [:empty] : args > >>> -- > >>> Posted via http://www.ruby-forum.com/. > >>> > >>> > > > > > > > --001485eba2ccd2f59e04831c10fb--