7stud2
(7stud --)
3 September 2012 11:38
1
dear all
----------<8-------------
------------1-----------
if A=13
do something
else
raise some warning
end
-------------2-----------
if A=14
do something #(the same as 1 )
else
raise some warning #(the same as 1)
end
------------8>----------------
so, is there other word like
if A is in[13..14]
else
raise some warning #(the same as 1)
end
any help would be appropriated.
Edward
···
--
Posted via http://www.ruby-forum.com/ .
7stud2
(7stud --)
3 September 2012 11:47
2
Hi,
Be careful not to mix up "=" (assignment) and "==".
You can either use the logical "or":
if A == 13 or A == 14
...
Or you can use Array#include:
if [13, 14].include? A
...
The latter doesn't really make sense here, but it's useful when you have
a lot of values.
In your specific case it might make more sense to put the error handling
on top:
raise ... unless A == 13 or A == 14
# do something
···
--
Posted via http://www.ruby-forum.com/ .
7stud2
(7stud --)
4 September 2012 01:32
3
Thanks Jan, robert.
Regards
Edward.
···
--
Posted via http://www.ruby-forum.com/ .
Robert_K1
(Robert K.)
3 September 2012 12:18
4
And for integers we can also facilitate ranges
irb(main):001:0> (13..17).include? 15
=> true
Kind regards
robert
···
On Mon, Sep 3, 2012 at 1:47 PM, Jan E. <lists@ruby-forum.com> wrote:
You can either use the logical "or":
if A == 13 or A == 14
...
Or you can use Array#include:
if [13, 14].include? A
...
The latter doesn't really make sense here, but it's useful when you have
a lot of values.
--
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/