Ruby | String bytes Method
Last Updated :
07 Jan, 2020
Improve
bytes is a String class method in Ruby which is used to return an array of the bytes for the given string.
Ruby
Output:
Ruby
Output:
Syntax: str.bytes Parameters: Here, str is the specified string. Returns: An array of bytes.Example 1:
# Ruby program to demonstrate
# the bytes method
# Taking a string and
# using the method
puts "String".bytes
83 116 114 105 110 103Example 2:
# Ruby program to demonstrate
# the bytes method
# Taking a string and
# using the method
puts "ABCD".bytes
65 66 67 68