In Ruby, the getbyte() method is used to return a byte or
int getbyte( int index)
This method takes the parameter index. It represents the index position of the character whose byte value we want to get.
It returns an integer value that is the byte representation of a character.
# create a stringstr = "Edpresso";# get byte of some characters and printing themputs str.getbyte(0) # first characterputs str.getbyte(3) # fourth characterputs str.getbyte(7) # last character
str.getbyte() method on the string str to get the bytes of several characters. We print these using puts. Next, we pass the index position value of the characters to getbyte(). It returns the bytes of the characters.When the code above is run, the byte value of the characters is printed to the console.