T
timr
consider the following irb session;
#note the following weird case!!!
three characters is still nil.
So, to summarize, when indexing a position beyond the length of a
string, ruby returns nil. But when indexing a slice beyond the length
of a string, ruby returns an empty string "" for the first index
beyond and then nil.
I don't like that this passes
assert "foo"[3] != "foo"[3,1]
Matz, you are so smart, but this does not follow the principle of
least surprise!!! $B$3$s$J$3$H$O$X$s$8$c$J$$$9$+!#(B
I would appreciate it if anyone can explain how this might make
sense...but please only try if you really believe it is a defensible
behavior for the language.
Thanks,
Tim
=> nil"foo"[0] => "f"
"foo"[1] => "o"
"foo"[2] => "o"
"foo"[3] => nil
"foo"[4]
=> "o""foo"[0,3] => "foo"
"foo"[1,3] => "oo"
"foo"[2,3]
#note the following weird case!!!
=> ""$B!!!!(B#this should be nil in my mind, "foo"[3] is nil, and taking"foo"[3,3]
three characters is still nil.
=> nil"foo"[4,3]
So, to summarize, when indexing a position beyond the length of a
string, ruby returns nil. But when indexing a slice beyond the length
of a string, ruby returns an empty string "" for the first index
beyond and then nil.
I don't like that this passes
assert "foo"[3] != "foo"[3,1]
Matz, you are so smart, but this does not follow the principle of
least surprise!!! $B$3$s$J$3$H$O$X$s$8$c$J$$$9$+!#(B
I would appreciate it if anyone can explain how this might make
sense...but please only try if you really believe it is a defensible
behavior for the language.
Thanks,
Tim