Ruby | String encoding Method
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 |
chevron_right
filter_none
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 |
chevron_right
filter_none
Output:
UTF-8 UTF-8
Recommended Posts:
- Ruby | Symbol encoding function
- Ruby | Regexp encoding() function
- Ruby | String =~ Method
- Ruby | String << Method
- Ruby | String chr Method
- Ruby | String == method
- Ruby | String * Method
- Ruby | String === Method
- Ruby | String + Method
- Ruby | String eql? Method
- Ruby | String <=> Method
- Ruby | String hex Method
- Ruby | String center() method
- Ruby | String include? Method
- Ruby | String crypt Method
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



