Open In App

Ruby | String chr Method

Improve
Improve
Like Article
Like
Save
Share
Report

chr is a String class method in Ruby which is used to return a one-character string at the beginning of the string.

Syntax:str.chr

Parameters: Here, str is the given string.

Returns: A one-character string at the beginning of the string.

Example 1:




# Ruby program to demonstrate 
# the chr method 
       
# Taking a string and 
# using the method 
puts "Ruby".chr
puts "Method".chr


Output:

R
M

Example 2:




# Ruby program to demonstrate 
# the chr method 
       
# Taking a string and 
# using the method 
puts "String".chr
puts "Class".chr


Output:

S
C

Last Updated : 13 Dec, 2019
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads