Just getting back to this thread... looks like there's been some good
discussion.
One thing that hasn't been mentioned yet, and which unfortunately I
couldn't really address in the talk without a long tangent, is *why *would
you want to write code like this in the first place? Is a proc in a case
statement anything but a useless, overly-clever bit of language esoterica?
In the describe_color example from the slides, it really is kind of
overkill. I wouldn't recommend actually writing code like that instead of
using if color.blueish?...elsif color.reddish?...etc.
Where it's more useful is when you parameterise the case statement by
passing a variable that contains a proc. I'm having a hard time thinking of
a good, concise example of that, but maybe someone else has one.
On Friday, August 1, 2014 6:01:46 PM UTC+10, Marky Mark wrote:
>
> Um, I just wrote my original question out and stared at it some more and
> realised it was a stupid question to begin with :-(
>
> But the more I think about it the more I'm confused (and maybe this is
> where hearing what Tim said at the time would help).
>
> Conceptually I see "case a when b ... when c ... else ..." as being the
> same as "if a === b ... elsif a === c ... else ..." (as indeed slides 67-69
> show) but that seems to fail for slide 62's use of proc:
>
> case color
> when proc { |color| color.more_blue? }
> "blueish"
>
> because comparing color with what the proc yields (true or false) surely
> doesn't work. Am I misunderstanding what proc yields?
>
> On Friday, August 1, 2014 5:08:06 PM UTC+10, Dave Burt wrote:
>>
>> Thanks for the notes, Tim!
>>
>> Mark, post your case questions here!
>>
>> On the same topic, here is an article by Why on another feature of Ruby's
>> case statements: you can *splat* an array like this:
>>
>> foo = 3
>> ARRAY = [/abc/, Hash, 1..5]
>> case foo; when *ARRAY; 'included'; else "doesn't === anything in the
>> array"; end
>>
>> http://viewsourcecode.org/why/redhanded/bits/wonderOfTheWhenBeFlat.html
>>
>> Cheers,
>> Dave
>>
>>
>> On Fri, Aug 1, 2014 at 2:53 PM, Marky Mark <[email protected]> wrote:
>>
>>> Just slides though, no soundtrack? Familiar with case statements as I am
>>> in general, I can't help thinking I'm missing a little of the
>>> subtlety/reasoning w.r.t Ruby. I do have one or two stupid questions.
>>> Should I post here or ask you privately?
>>>
>>>
>>> On Thursday, July 31, 2014 3:04:32 PM UTC+10, Tim Moore wrote:
>>>>
>>>> Yes, I'll echo Dave's thoughts: thanks to the organisers and the
>>>> substitute host!
>>>>
>>>> My slides are up at https://speakerdeck.com/
>>>> timmoore/rubys-magical-case-statement and http://www.slideshare.net/
>>>> timothymoore/rubys-magical-case-statement (take your pick)
>>>>
>>>> On Thursday, July 31, 2014 8:52:42 AM UTC+10, Dave Burt wrote:
>>>>>
>>>>> Hi,
>>>>>
>>>>> Thanks to the organisers and speakers for another great evening.
>>>>>
>>>>> May I ask again for links to any of the talks that are available?
>>>>>
>>>>> I think Duncan referenced his Github repo https://github.com/
>>>>> duncan-bayne/presentations
>>>>>
>>>>> Cheers,
>>>>> Dave
>>>>>
>>>>>
>>>>> On Fri, Jul 25, 2014 at 1:17 PM, Mario Visic <[email protected]>
>>>>> wrote:
>>>>>
>>>>>> Hi All
>>>>>>
>>>>>> The Melbourne Ruby meet will be happening next wednesday evening (the
>>>>>> 30th July), with our usual array of entertaining talks, delicious food,
>>>>>> tasty beverages, and delightful company (that’s you!).
>>>>>>
>>>>>> WHEN: Wednesday 30th July, arrive at 6pm for a 6:30pm start,
>>>>>> wrapping up around 9pm.
>>>>>> WHERE: Inspire9, Level 1, 41-43 Stewart Street
>>>>>> WHAT: Three speakers, plus socialising, good food (not pizza) and
>>>>>> drinks.
>>>>>>
>>>>>> Our line-up this month is:
>>>>>> Jordan Lewis + Luke Arndt - Styleguide driven development
>>>>>> Duncan Bayne - There’s no such thing as magic - tools and techniques
>>>>>> for Ruby developers
>>>>>> Tim Moore - Case Statements and ===
>>>>>>
>>>>>> All of these details are repeated on Meetup, for those who prefer
>>>>>> that as their source of event information:
>>>>>> http://www.meetup.com/Ruby-On-Rails-Oceania-Melbourne/
>>>>>> events/175705562/
>>>>>>
>>>>>> Yet again, food is sponsored by Envato, Lookahead Search and
>>>>>> Redbubble, the drinks by Zendesk, and the space by Inspire9.
>>>>>>
>>>>>> If you've any questions or thoughts, get in touch - we're looking
>>>>>> forward to seeing you all there :)
>>>>>>
>>>>>> --
>>>>>> Mario & Pat
>>>>>>
>>>>>> --
>>>>>> You received this message because you are subscribed to the Google
>>>>>> Groups "Ruby or Rails Oceania" group.
>>>>>> To unsubscribe from this group and stop receiving emails from it,
>>>>>> send an email to [email protected].
>>>>>> To post to this group, send email to [email protected].
>>>>>> Visit this group at http://groups.google.com/group/rails-oceania.
>>>>>> For more options, visit https://groups.google.com/d/optout.
>>>>>>
>>>>>
>>>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "Ruby or Rails Oceania" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an email to [email protected].
>>> To post to this group, send email to [email protected].
>>>
>>> Visit this group at http://groups.google.com/group/rails-oceania.
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>
>>
--
You received this message because you are subscribed to the Google Groups "Ruby
or Rails Oceania" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/rails-oceania.
For more options, visit https://groups.google.com/d/optout.