# Array.include? I do not seem to GET it

**URL:** <https://www.ruby-forum.com/t/array-include-i-do-not-seem-to-get-it/172094>\
**Category:** Ruby\
**Created:** [July 14, 2009, 6:02pm UTC](https://www.ruby-forum.com/t/array-include-i-do-not-seem-to-get-it/172094 "2009-07-14T18:02:16Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![byrnejb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/d2c977/32.png) [@byrnejb](https://www.ruby-forum.com/u/byrnejb)\
**Post date:** [July 14, 2009, 6:02pm UTC](https://www.ruby-forum.com/t/array-include-i-do-not-seem-to-get-it/172094/1 "2009-07-14T18:02:16Z")

</div>

I have this set of constructs:

def initialize(argv)  
@argv = argv  
end

def start  
puts @argv.class  
puts @argv.size  
puts @argv  
@argv.include?(’–update’) ? puts(“Includes update”) : puts(“No  
–update”)  
…

which produces this output for a given input:

Array  
4  
‘-s /doc/data/fx-noon-all-2009-04-15.xml’  
‘-f csv’  
‘-o forex\_testing’  
‘–update’  
‘-t’  
No --update

Now. Here are the posers that I cannot answer.

Why is #size == 4 rather than 5; and

Why is ‘–update’ listed when printing the array but it is not found in  
the same array by #include?(’–update’). What is it that I am getting  
wrong here?

---

<div class="post-metadata">

**Author:** ![byrnejb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/d2c977/32.png) [@byrnejb](https://www.ruby-forum.com/u/byrnejb)\
**Post date:** [July 14, 2009, 6:07pm UTC](https://www.ruby-forum.com/t/array-include-i-do-not-seem-to-get-it/172094/2 "2009-07-14T18:07:17Z")

</div>

P.S. This gives exactly the same output

```
  @argv.include?("'--update'") ? puts("Includes update") : puts("No 

```

–update")

---

<div class="post-metadata">

**Author:** ![byrnejb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/d2c977/32.png) [@byrnejb](https://www.ruby-forum.com/u/byrnejb)\
**Post date:** [July 14, 2009, 6:08pm UTC](https://www.ruby-forum.com/t/array-include-i-do-not-seem-to-get-it/172094/3 "2009-07-14T18:08:40Z")

</div>

> Why is #size == 4 rather than 5; and

maybe you could add a  
puts @argv.inspect to see what’s going on ?  
=r

---

<div class="post-metadata">

**Author:** ![byrnejb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/d2c977/32.png) [@byrnejb](https://www.ruby-forum.com/u/byrnejb)\
**Post date:** [July 14, 2009, 6:19pm UTC](https://www.ruby-forum.com/t/array-include-i-do-not-seem-to-get-it/172094/4 "2009-07-14T18:19:10Z")

</div>

Am Dienstag 14 Juli 2009 18:02:19 schrieb James B.:

> Array  
> Why is #size == 4 rather than 5; and  
> arr = [“1”, “2”, “3\n4”, “5”]  
> puts arr  
> puts “size is #{arr.size}”

will output:  
1  
2  
3  
4  
5  
size is 4

Meaning: if some of the strings in the array contain newlines, you can  
not  
tell from puts’ output how many items are in the array.

> Why is ‘–update’ listed when printing the array but it is not found in  
> the same array by #include?(’–update’). What is it that I am getting  
> wrong here?

puts ["–update"]  
will output:  
–update

puts ["’–update’"]  
will output:  
‘–output’

In other words, puts will only surround the string with quotes if the  
string  
actually contains quotes.  
Generally you should use p instead of puts for your debug output so you  
can  
more easily tell the exact contents of the array.

HTH,  
Sebastian

---

<div class="post-metadata">

**Author:** ![byrnejb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/d2c977/32.png) [@byrnejb](https://www.ruby-forum.com/u/byrnejb)\
**Post date:** [July 14, 2009, 6:20pm UTC](https://www.ruby-forum.com/t/array-include-i-do-not-seem-to-get-it/172094/5 "2009-07-14T18:20:50Z")

</div>

Roger P. wrote:

> > Why is #size == 4 rather than 5; and
> 
> maybe you could add a  
> puts @argv.inspect to see what’s going on ?  
> =r

```
  puts @argv.class
  puts @argv.size
  puts @argv
  puts @argv.inspect
  @argv.include?("--update") ? puts("Includes update") : puts("No 

```

–update")  
puts @argv.index("’–update’")

Array  
5  
‘-s /doc/data/fx-noon-all-2009-04-15.xml’  
‘-f csv’  
‘-o forex\_testing’  
‘–update’  
‘-t’  
["’-s /doc/data/fx-noon-all-2009-04-15.xml’ ", "’-f csv’ ", "’-o  
forex\_testing’ ", "’–update’ ", "’-t’ "]  
No --update  
nil

Excellent suggestion. The trailing space … Sigh…

Thanks!

---

<div class="post-metadata">

**Author:** ![byrnejb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/d2c977/32.png) [@byrnejb](https://www.ruby-forum.com/u/byrnejb)\
**Post date:** [July 14, 2009, 6:26pm UTC](https://www.ruby-forum.com/t/array-include-i-do-not-seem-to-get-it/172094/6 "2009-07-14T18:26:43Z")

</div>

Roger P. wrote:

> maybe you could add a  
> puts @argv.inspect to see what’s going on ?  
> =r

```
  puts @argv.class
  puts @argv.size
  puts @argv
  puts @argv.inspect
  @argv.include?("'--update'") ? puts("Includes update") : puts("No 

```

–update")  
puts @argv.index("’–update’")

Array  
5  
‘-s /doc/data/fx-noon-all-2009-04-15.xml’  
‘-f csv’  
‘-o forex\_testing’  
‘–update’  
‘-t’  
["’-s /doc/data/fx-noon-all-2009-04-15.xml’ ", "’-f csv’ ", "’-o  
forex\_testing’ ", “’–update’”, “’-t’”]  
Includes update  
3

Thank you all very much.
