Range on strings.

V

Vikrant Chaudhary

Hi,
If I do -

('A'..'Z').include?('AA')

It returns "true", while

('A'..'Z').to_a.include?('AA')

(of course) returns "false". Is it intentional or possibly a bug?
I'm using ruby 1.8.7 (2010-01-10 patchlevel 249) [x86_64-linux] on
Ubuntu 10.04 x64
 
M

MrZombie

Is it intentional or possibly a bug?
I'm using ruby 1.8.7 (2010-01-10 patchlevel 249) [x86_64-linux] on
Ubuntu 10.04 x64

Mac OS X Snow Leopard running Ruby 1.9.1, same behavior.

I notice that it returns false if no element of the string is included
in the range.

For example, given r = ('A'..'Z'): r.include?('RUBY') # returns true
and: r.include?('Ruby') # also true
but: r.include?('ruby') # is false.
 
V

Vikrant Chaudhary

Hi,
If I do -

('A'..'Z').include?('AA')

It returns "true", while

('A'..'Z').to_a.include?('AA')

(of course) returns "false". Is it intentional or possibly a bug?
I'm using ruby 1.8.7 (2010-01-10 patchlevel 249) [x86_64-linux] on
Ubuntu 10.04 x64

Probably because the way Strings are compared, "AA" < "Z" #=> true
 
M

MrZombie

Hi,
If I do -

('A'..'Z').include?('AA')

It returns "true", while

('A'..'Z').to_a.include?('AA')

(of course) returns "false". Is it intentional or possibly a bug?
I'm using ruby 1.8.7 (2010-01-10 patchlevel 249) [x86_64-linux] on
Ubuntu 10.04 x64

Probably because the way Strings are compared, "AA" < "Z" #=> true

Just for the kicks, I tried with ('a'..'z').include? 'aa'

Guess what? False.
 
M

Michael W Ryder

Vikrant said:
Hi,
If I do -

('A'..'Z').include?('AA')

It returns "true", while

('A'..'Z').to_a.include?('AA')

(of course) returns "false". Is it intentional or possibly a bug?
I'm using ruby 1.8.7 (2010-01-10 patchlevel 249) [x86_64-linux] on
Ubuntu 10.04 x64

Using ruby 1.9.1 and Windows Vista both examples return false.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,001
Messages
2,570,254
Members
46,850
Latest member
VMRKlaus8

Latest Threads

Top