Case when

Hi,

Is there an abbrevation for using more values in one clause?
case
when x==false or x==nil ...
when x==1 or x==3 ...
when x==2 ...
when x==4 ...
end

# I want a short form, but that does not work...
# like:
case x
when false or nil
when 1 or 3
when 2
when 4

Any other way to use the second form ?

thanks
Opti

​Ruby syntax:
https://docs.ruby-lang.org/en/2.4.0/syntax/control_expressions_rdoc.html#label-case+Expression

···

On 4 January 2017 at 08:34, Die Optimisten <inform@die-optimisten.net> wrote:

Hi,

Is there an abbrevation for using more values in one clause?
case
when x==false or x==nil ...
when x==1 or x==3 ...
when x==2 ...
when x==4 ...
end

# I want a short form, but that does not work...
# like:
case x
when false or nil
when 1 or 3
when 2
when 4

Any other way to use the second form ?

thanks
Opti

~~~
case x
when false, nil
when 1, 3
when 2
when 4
end
~~~

Please remember to refer to the manual.

Cheers
--
  Matthew Kerwin
  http://matthew.kerwin.net.au/

Eli Sadoff, I thought the purpose of such a list was to learn stuff. Your
statement comes across as being elitist, if not downright condescending.
But, hey, as you said, there's always stack overflow!

You see, sometimes us mortals seek advice from gurus like you for what you
may think are simple things, or things easy to find elsewhere, but there's
generally more to an answer than providing a link to some documentation.
I'm pretty sure Opti, the original requester, took the time to do a Google
search before posting his/her question!

I'm glad some experts on this list are taking some of their precious time
to answer "dumb" questions. Been learning quite a bit from that.

Sorry if we rubes of all sorts are "crowding your email," dude.

Eat your veggies and have yourself a nice day!

···

On Tue, Jan 3, 2017 at 3:12 PM, Eli Sadoff <snood1205@gmail.com> wrote:

Can discussion like this please be curbed a bit?
I feel like the ruby irc channel is a better place for asking questions
like this than the mailing list.
I have no inherent problems with helping those with tricky questions, but
the answers to this can be found in the manual and on stack overflow, so I
feel that this is just crowding my email and does not seem to be in line
with a lot of the other discussions on the mailing list.

Cheers
-Eli

On Tue, Jan 3, 2017 at 5:47 PM, Matthew Kerwin <matthew@kerwin.net.au> > wrote:

On 4 January 2017 at 08:34, Die Optimisten <inform@die-optimisten.net> >> wrote:

Hi,

Is there an abbrevation for using more values in one clause?
case
when x==false or x==nil ...
when x==1 or x==3 ...
when x==2 ...
when x==4 ...
end

# I want a short form, but that does not work...
# like:
case x
when false or nil
when 1 or 3
when 2
when 4

Any other way to use the second form ?

thanks
Opti

​Ruby syntax: https://docs.ruby-lang.org/en/2.4.0/syntax/control_
expressions_rdoc.html#label-case+Expression

~~~
case x
when false, nil
when 1, 3
when 2
when 4
end
~~~

Please remember to refer to the manual.

Cheers
--
  Matthew Kerwin
  http://matthew.kerwin.net.au/

Unsubscribe: <mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk&gt;

Unsubscribe: <mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk&gt;

Can discussion like this please be curbed a bit?
I feel like the ruby irc channel is a better place for asking questions
like this than the mailing list.
I have no inherent problems with helping those with tricky questions, but
the answers to this can be found in the manual and on stack overflow, so I
feel that this is just crowding my email and does not seem to be in line
with a lot of the other discussions on the mailing list.

Cheers
-Eli

···

On Tue, Jan 3, 2017 at 5:47 PM, Matthew Kerwin <matthew@kerwin.net.au> wrote:

On 4 January 2017 at 08:34, Die Optimisten <inform@die-optimisten.net> > wrote:

Hi,

Is there an abbrevation for using more values in one clause?
case
when x==false or x==nil ...
when x==1 or x==3 ...
when x==2 ...
when x==4 ...
end

# I want a short form, but that does not work...
# like:
case x
when false or nil
when 1 or 3
when 2
when 4

Any other way to use the second form ?

thanks
Opti

​Ruby syntax: https://docs.ruby-lang.org/en/2.4.0/syntax/
control_expressions_rdoc.html#label-case+Expression

~~~
case x
when false, nil
when 1, 3
when 2
when 4
end
~~~

Please remember to refer to the manual.

Cheers
--
  Matthew Kerwin
  http://matthew.kerwin.net.au/

Unsubscribe: <mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk&gt;

I'm terribly sorry.

I misread Ruby mailing-list this was. I misread this as [ruby-core] instead
of [ruby-lang]. I'm very sorry. I would not have sent that out had I
realized which this was. I sincerely apologize.

Sorry
-Eli

···

On Tue, Jan 3, 2017 at 7:25 PM, Marc Chanliau <marc.chanliau@gmail.com> wrote:

Eli Sadoff, I thought the purpose of such a list was to learn stuff. Your
statement comes across as being elitist, if not downright condescending.
But, hey, as you said, there's always stack overflow!

You see, sometimes us mortals seek advice from gurus like you for what you
may think are simple things, or things easy to find elsewhere, but there's
generally more to an answer than providing a link to some documentation.
I'm pretty sure Opti, the original requester, took the time to do a Google
search before posting his/her question!

I'm glad some experts on this list are taking some of their precious time
to answer "dumb" questions. Been learning quite a bit from that.

Sorry if we rubes of all sorts are "crowding your email," dude.

Eat your veggies and have yourself a nice day!

On Tue, Jan 3, 2017 at 3:12 PM, Eli Sadoff <snood1205@gmail.com> wrote:

Can discussion like this please be curbed a bit?
I feel like the ruby irc channel is a better place for asking questions
like this than the mailing list.
I have no inherent problems with helping those with tricky questions, but
the answers to this can be found in the manual and on stack overflow, so I
feel that this is just crowding my email and does not seem to be in line
with a lot of the other discussions on the mailing list.

Cheers
-Eli

On Tue, Jan 3, 2017 at 5:47 PM, Matthew Kerwin <matthew@kerwin.net.au> >> wrote:

On 4 January 2017 at 08:34, Die Optimisten <inform@die-optimisten.net> >>> wrote:

Hi,

Is there an abbrevation for using more values in one clause?
case
when x==false or x==nil ...
when x==1 or x==3 ...
when x==2 ...
when x==4 ...
end

# I want a short form, but that does not work...
# like:
case x
when false or nil
when 1 or 3
when 2
when 4

Any other way to use the second form ?

thanks
Opti

​Ruby syntax: https://docs.ruby-lang.org/en/2.4.0/syntax/control_e
xpressions_rdoc.html#label-case+Expression

~~~
case x
when false, nil
when 1, 3
when 2
when 4
end
~~~

Please remember to refer to the manual.

Cheers
--
  Matthew Kerwin
  http://matthew.kerwin.net.au/

Unsubscribe: <mailto:ruby-talk-request@ruby-lang.org
?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk&gt;

Unsubscribe: <mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk&gt;

Unsubscribe: <mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk&gt;

Marc, I disagree; nobody is paid for answering posts around here,
and it's an established practice and a question of good netiquette
to do some basic research before asking. There have been examples
in the past of posters that simply refused to do any reading on
their own, flooding the list with the most basic questions and
annoying away a lot of the regular and more experienced contributors.
(And this is generally speaking, I'm _not_ referring to the OP.)

Regarding the specific question: my first search ("ruby case when")
produced more than enough examples of the usage, including the
multi-value variant. I certainly do not say that such an answer
to the OP was necessary (and, as Eli explained, was the result
of a misunderstanding anyway), but considering this, your reply
to Eli also IMO seems harsher than might have been necessary.

Regards,
Marcus

···

Am 04.01.2017 um 01:25 schrieb Marc Chanliau:

Your statement comes across as being elitist, if not downright
condescending. But, hey, as you said, there's always stack overflow!

--
GitHub: stomar (Marcus Stollsteimer) · GitHub
PGP: 0x6B3A101A

I agree. A reminder for us all:
https://en.wiktionary.org/wiki/MINASWAN

Kind regards

robert

···

On Thu, Jan 5, 2017 at 5:45 PM, <sto.mar@web.de> wrote:

Am 04.01.2017 um 01:25 schrieb Marc Chanliau:

Your statement comes across as being elitist, if not downright
condescending. But, hey, as you said, there's always stack overflow!

Marc, I disagree; nobody is paid for answering posts around here,
and it's an established practice and a question of good netiquette
to do some basic research before asking. There have been examples
in the past of posters that simply refused to do any reading on
their own, flooding the list with the most basic questions and
annoying away a lot of the regular and more experienced contributors.
(And this is generally speaking, I'm _not_ referring to the OP.)

Regarding the specific question: my first search ("ruby case when")
produced more than enough examples of the usage, including the
multi-value variant. I certainly do not say that such an answer
to the OP was necessary (and, as Eli explained, was the result
of a misunderstanding anyway), but considering this, your reply
to Eli also IMO seems harsher than might have been necessary.

--
[guy, jim, charlie].each {|him| remember.him do |as, often| as.you_can
- without end}
http://blog.rubybestpractices.com/