# String#slice! doc bug?

**URL:** <https://www.ruby-forum.com/t/string-slice-doc-bug/79998>\
**Category:** Ruby\
**Created:** [December 20, 2006, 7:53pm UTC](https://www.ruby-forum.com/t/string-slice-doc-bug/79998 "2006-12-20T19:53:18Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![danielb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/c57346/32.png) [@danielb](https://www.ruby-forum.com/u/danielb)\
**Post date:** [December 20, 2006, 7:53pm UTC](https://www.ruby-forum.com/t/string-slice-doc-bug/79998/1 "2006-12-20T19:53:18Z")

</div>

-----BEGIN PGP SIGNED MESSAGE-----  
Hash: SHA1

Hi all,

Ruby 1.8.4 and 1.8.5

The docs for String#slice! say, “The forms that take a Fixnum will raise  
an IndexError if the value is out of range.”

However, I cannot duplicate this behavior. Whenever I try to force an  
IndexError, I just get back nil, i.e. the same behavior as String.slice.

irb(main):001:0\> VERSION  
=\> “1.8.4”  
irb(main):002:0\> s = “hello”  
=\> “hello”  
irb(main):003:0\> s.slice!(-5,-99)  
=\> nil  
irb(main):004:0\> s  
=\> “hello”  
irb(main):005:0\> s.slice!(-5,100)  
=\> “hello”  
irb(main):006:0\> s  
=\> “”

I tried a few other things with no luck. Am I missing the proper test  
case?

Thanks,

Dan  
-----BEGIN PGP SIGNATURE-----  
Version: GnuPG v1.4.2 (GNU/Linux)  
Comment: Using GnuPG with SUSE - [http://enigmail.mozdev.org](http://enigmail.mozdev.org)

iD8DBQFFiLDq3p/dorzCFX0RAtzeAJ9M8622KzUTHfeiwAQPdjcthjmrMACeO3qk  
v/9pNgyUiGziHHgi1Vlht9w=  
=lGlO  
-----END PGP SIGNATURE-----
