Using String#slice with a symbol argument

Currently, ruby 1.8.6. has the following behavior:

‘ruby’[:en] #=> nil

The reason is that the symbol is converted to an integer using
to_int. But this is never useful, and can be a source of obscure bugs
when your variable contains a string instead of an hash.

Wouldn’t raising an exception be more appropriate?

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs