Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.ruby > #6573

Re: what's up with return *splat ?

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!de-l.enfer-du-nord.net!feeder2.enfer-du-nord.net!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From Robert Klemme <shortcutter@googlemail.com>
Newsgroups comp.lang.ruby
Subject Re: what's up with return *splat ?
Date Fri, 22 Jun 2012 18:24:10 +0200
Lines 71
Message-ID <a4jkhpFss0U1@mid.individual.net> (permalink)
References <0fae13bb-3468-4883-b855-17950bee1117@t2g2000pbl.googlegroups.com> <a3pq3mFm27U1@mid.individual.net> <2a77ca16-20d5-4700-bf7d-0a746f4730d6@e7g2000pbg.googlegroups.com> <a43eidFbv2U1@mid.individual.net> <9040131a-0ad1-4736-a0e3-693b9cf58a27@g4g2000pbn.googlegroups.com>
Mime-Version 1.0
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 7bit
X-Trace individual.net fVu3aOC5UxUnGd66s4Cw/A4VxpAnddONiX87oiU8dhCPbnxG14e7qAezRY3n3+H0U=
Cancel-Lock sha1:lab/w0cNSZ2OG+PGspggzvPiyj4=
User-Agent Mozilla/5.0 (Windows NT 6.0; WOW64; rv:13.0) Gecko/20120614 Thunderbird/13.0.1
In-Reply-To <9040131a-0ad1-4736-a0e3-693b9cf58a27@g4g2000pbn.googlegroups.com>
Xref csiph.com comp.lang.ruby:6573

Show key headers only | View raw


On 22.06.2012 01:24, Phlip wrote:
> Tx for the experiment; it confirmed mine.

Strange.  I said

> I get different results:
> ...

>> I think you use a function in one of two ways: either you expect one
>> result and that can be nil or not, or you expect multiple replies and
>> assign them to different variables which can either be nil or not.
>>
>> What practical use case is impaired by the difference?
>
> When I write an assertion, I know the ordinality of the expected
> result.
>
>    note1, note2 = assert_latest User.notes do
>      User.create_notes()
>    end
>
>    assert{ user.notes == [note1, note2] }
>
>    frob = assert_latest Frob do
>      production_code_creating_frobs()
>    end
>
>    assert{ frob.member == 42 }
>
> I want the assertions to break, with simple syntax errors, if the
> ordinality is wrong.

You cannot get syntax errors for this.  This is checked at runtime and 
not at parse time.

> If assert_latest only returned arrays, that would
> cause clutter like this:
>
>    frobs = assert_latest Frob do
>      production_code_creating_frobs()
>    end
>
>    assert{ frobs.count == 1 and frobs[0].member == 42 }
>
> Instead of testing the count, I want to simply use the result as if
> it's what I expect, and then fail as early as possible if it isn't.

Note that you can do this in 1.9.* and 1.8.7 (the comma):

irb(main):002:0> def f(*a) a end
=> nil
irb(main):003:0> f 1,2
=> [1, 2]
irb(main):004:0> x=f 1,2
=> [1, 2]
irb(main):005:0> x
=> [1, 2]
irb(main):006:0> x,=f 1,2
=> [1, 2]
irb(main):007:0> x
=> 1

Kind regards

	robert

-- 
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/

Back to comp.lang.ruby | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

what's up with return *splat ? Phlip <phlip2005@gmail.com> - 2012-06-12 11:48 -0700
  Re: what's up with return *splat ? Robert Klemme <shortcutter@googlemail.com> - 2012-06-12 23:19 +0200
    Re: what's up with return *splat ? Phlip <phlip2005@gmail.com> - 2012-06-12 17:10 -0700
      Re: what's up with return *splat ? Robert Klemme <shortcutter@googlemail.com> - 2012-06-16 15:04 +0200
        Re: what's up with return *splat ? Phlip <phlip2005@gmail.com> - 2012-06-21 16:24 -0700
          Re: what's up with return *splat ? Robert Klemme <shortcutter@googlemail.com> - 2012-06-22 18:24 +0200
            Re: what's up with return *splat ? Phlip <phlip2005@gmail.com> - 2012-06-22 10:02 -0700
              Re: what's up with return *splat ? Robert Klemme <shortcutter@googlemail.com> - 2012-06-22 23:36 +0200
                Re: what's up with return *splat ? Phlip <phlip2005@gmail.com> - 2012-06-24 16:27 -0700

csiph-web