3 ms·
It just occurred to me that Ruby's symbols are pretty much the same as Rust's string slices. No?
by endorphine 1y ago
It just occurred to me that Ruby's symbols are pretty much the same as Rust's string slices. No?
- deleted 1y ago[deleted]
- jbverschoor 1y agoNo. A symbol is basically a constant such as for example HTTP_NOT_FOUND. The difference is that you don’t assign it a number, which means less decisions during development. Another difference is that it will be printed as the string, so no to_string boilerplate. The other colon path: is used for named parameters/keyword args. It’s the same syntax as a hash/dict, but as a parameter it does not have a default value in this case. The old syntax, but still supported for hash/dict was “key => value” Rust’s string slices are the equivalent of Ruby’s slices of an array: myarr[5..18]