How do I extend the String class, and attach a method named to_bytes
?
String#bytes
returns enumerator through string bytes.
"asd".bytes => [97, 115, 100]
In Ruby 1.9.3 the #bytes
was returning an Enumerator so you had to add .to_a
to convert it to an Array. Since 2.3 or maybe even earlier you don't have to add it anymore.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With