From: Aldric Giacomoni Date: 2010-03-31T21:22:02+09:00 Subject: Re: Ruby Koans: will this method ever return :empty? Steve Kim wrote: > I'm having trouble understanding the return statement for this > particular > koan: > > class MessageCatcher > def add_a_payload(*args) > return :empty unless args > args > end > end > > mc = MessageCatcher.new > mc.add_a_payload # [] > mc.add_a_payload(1) # [1] > > Is it possible to have this method return :empty? > > > skim Sure.. Building up a little on the previous post which gave you the answer: class MessageCatcher def add_a_payload *args args.empty? :empty : args end end Although as far as form and style go, it's very bad manners to have a method return either an array or a symbol ;-) It's better to always return an array, or always return a symbol - so it's easier to use. For instance: args.empty? [:empty] : args Cheers. -- Posted via http://www.ruby-forum.com/.