Ruby | String encoding Method Last Updated : 12 Dec, 2019 Improve Improve Like Article Like Save Share Report encoding is a String class method in Ruby which is used to return the Encoding object that represents the encoding of object. Syntax: str.encoding Parameters: Here, str is the given string. Returns: An encoding object. Example 1: # Ruby program to demonstrate # the encoding method # Taking a string and # using the method puts "R\xC3\xA9sum\xC3\xA9".encoding puts "Ruby\n\n".encoding Output: UTF-8 UTF-8 Example 2: # Ruby program to demonstrate # the encoding method # Taking a string and # using the method puts "Sample".encoding puts "Input\n\n".encoding Output: UTF-8 UTF-8 Like Article Suggest improvement Previous Ruby | String delete() Method Next Ruby | String end_with? Method Share your thoughts in the comments Add Your Comment Please Login to comment...