Forum: Ruby Why Array#include? not working withone liner integer arrays?

Posted by Love U Ruby (my-ruby)
on 2013-02-01 08:01
I was trying to write a one liner with integer array using
array#include?,which is not working.But the same is good with
character/string array.

C:\>irb
irb(main):001:0> a=[1,2,3]
=> [1, 2, 3]
irb(main):002:0> a.include?(1)
=> true
irb(main):003:0> a.include?(5)
=> false
irb(main):004:0> [1,2,3].inculde?(1)
NoMethodError: undefined method `inculde?' for [1, 2, 3]:Array
        from (irb):4
        from C:/Ruby193/bin/irb:12:in `<main>'
irb(main):007:0> b=[".vbs",".exe",".h"]
=> [".vbs", ".exe", ".h"]
irb(main):008:0> b.include?(".rb")
=> false
irb(main):009:0> [".vbs",".exe",".h"].include?(".rb")
=> false
irb(main):010:0> [1,2,3].inculde?(1)
NoMethodError: undefined method `inculde?' for [1, 2, 3]:Array
        from (irb):10
        from C:/Ruby193/bin/irb:12:in `<main>'
irb(main):011:0>

Could you please if is it possible what I am looking for or I did the
mistake?

Thanks
Posted by unknown (Guest)
on 2013-02-01 08:14
(Received via mailing list)
Am 01.02.2013 08:01, schrieb Arup Rakshit:
> I was trying to write a one liner with integer array using
> array#include?,which is not working.But the same is good with
> character/string array.

The error messages are telling you what the problem is (typos).
Posted by Justin Collins (Guest)
on 2013-02-01 08:18
(Received via mailing list)
On 01/31/2013 11:01 PM, Arup Rakshit wrote:
> => false
> irb(main):010:0> [1,2,3].inculde?(1)
> NoMethodError: undefined method `inculde?' for [1, 2, 3]:Array
>          from (irb):10
>          from C:/Ruby193/bin/irb:12:in `<main>'
> irb(main):011:0>
>
> Could you please if is it possible what I am looking for or I did the
> mistake?
>
> Thanks
>


You are misspelling "include" :)

-Justin
Posted by Prasadhnc C (Guest)
on 2013-02-01 08:19
(Received via mailing list)
`inculde?' -> check the spell
it should be include?
Posted by Love U Ruby (my-ruby)
on 2013-02-01 08:27
Justin Collins wrote in post #1094691:
> On 01/31/2013 11:01 PM, Arup Rakshit wrote:
>> => false
>> irb(main):010:0> [1,2,3].inculde?(1)
>> NoMethodError: undefined method `inculde?' for [1, 2, 3]:Array
>>          from (irb):10
>>          from C:/Ruby193/bin/irb:12:in `<main>'
>> irb(main):011:0>
>>
>> Could you please if is it possible what I am looking for or I did the
>> mistake?
>>
>> Thanks
>>
>
>
> You are misspelling "include" :)
>
> -Justin

The below should work right Logically ?

 @extension = File.extname(link_text)
 driver.find_element(:link, link_text).click if
[".pdf",".gif",".bmp","tif",".tiff","jpeg",".jpg"].include?(@extension)
Posted by Justin Collins (Guest)
on 2013-02-01 08:41
(Received via mailing list)
On 01/31/2013 11:27 PM, Arup Rakshit wrote:
>>> mistake?
>
>   @extension = File.extname(link_text)
>   driver.find_element(:link, link_text).click if
> [".pdf",".gif",".bmg","tif",".tiff","jpeg",".jpg"].include?(@extension)
>

Without knowing anything about what "driver" is, I would say yes.

-Justin
Posted by unknown (Guest)
on 2013-02-01 08:42
(Received via mailing list)
Am 01.02.2013 08:27, schrieb Arup Rakshit:
>>> mistake?
>
>   @extension = File.extname(link_text)
>   driver.find_element(:link, link_text).click if
> [".pdf",".gif",".bmg","tif",".tiff","jpeg",".jpg"].include?(@extension)

A friendly meant suggestion: Instead of writing posts like this
and the previous one you could spend your (and our) time better
with attentively reading the error messages, re-reading your code
**carefully** and simply trying whether it works on simple examples.

This applies here also:

   ext = 'gif'
   puts 'an image!'  if [".gif", "tif", '.jpg'].include?(ext)
   # no output

   ext = 'tif'
   puts 'an image!'  if [".gif", "tif", '.jpg'].include?(ext)
   # "an image"

You have to ask yourself:
is the dot supposed to be included in your @extension string or not?
Please log in before posting. Registration is free and takes only a minute.
Existing account (Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
No account? Register here.