A
Adam Shelly
I was playing around ranges of strings after that post about
irb(main):001:0> a =3D 1..10.to_a
(irb):1: warning: default `to_a' will be obsolete
ArgumentError: bad value for range
from (irb):1
irb(main):004:0> a =3D '1'..'10'.to_a
=3D> "1"..["10"]
irb(main):005:0> a.each{|i| p i}
TypeError: cannot convert Array into String
from (irb):5:in `each'
from (irb):5
irb(main):006:0> a
=3D> "1"..["10"]
irb(main):007:0> a.to_a
TypeError: cannot convert Array into String
from (irb):7:in `each'
from (irb):7:in `to_a'
from (irb):7
irb(main):015:0> r=3D'1'..[10]
=3D> "1"..[10]
irb(main):016:0> r.each{|i| p i}
TypeError: cannot convert Array into String
from (irb):16:in `each'
from (irb):16
irb(main):017:0> r.include? [5]
NoMethodError: undefined method `>' for false:FalseClass
from (irb):17:in `include?'
from (irb):17
Why can I create a Range where one end is a String and the other is an
Array? I can't do anything with it. I get an error if I create an
Fixnum..Array range, why don't I get one for the String..Array?
-Adam
I found something else strange when I made a typo:'1'..'10'.include? '2 #=3D> false
irb(main):001:0> a =3D 1..10.to_a
(irb):1: warning: default `to_a' will be obsolete
ArgumentError: bad value for range
from (irb):1
irb(main):004:0> a =3D '1'..'10'.to_a
=3D> "1"..["10"]
irb(main):005:0> a.each{|i| p i}
TypeError: cannot convert Array into String
from (irb):5:in `each'
from (irb):5
irb(main):006:0> a
=3D> "1"..["10"]
irb(main):007:0> a.to_a
TypeError: cannot convert Array into String
from (irb):7:in `each'
from (irb):7:in `to_a'
from (irb):7
irb(main):015:0> r=3D'1'..[10]
=3D> "1"..[10]
irb(main):016:0> r.each{|i| p i}
TypeError: cannot convert Array into String
from (irb):16:in `each'
from (irb):16
irb(main):017:0> r.include? [5]
NoMethodError: undefined method `>' for false:FalseClass
from (irb):17:in `include?'
from (irb):17
Why can I create a Range where one end is a String and the other is an
Array? I can't do anything with it. I get an error if I create an
Fixnum..Array range, why don't I get one for the String..Array?
-Adam