# Toutf8

**URL:** <https://www.ruby-forum.com/t/toutf8/183451>\
**Category:** Ruby\
**Created:** [February 14, 2010, 6:57pm UTC](https://www.ruby-forum.com/t/toutf8/183451 "2010-02-14T18:57:59Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![idiosyncratici](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/a88e4f/32.png) [@idiosyncratici](https://www.ruby-forum.com/u/idiosyncratici)\
**Post date:** [February 14, 2010, 6:57pm UTC](https://www.ruby-forum.com/t/toutf8/183451/1 "2010-02-14T18:57:59Z")

</div>

The string class has a couple of methods listed in ruby-doc such as:

String#toutf8 â†’ string

or

String#tosjis â†’ string

That’s diferent than how they list most of the other methods, e.g.:

str.strip =\> new\_str

I’m afraid I have no idea how to call a method like toutf8. I don’t  
know what’s up with # sign, either. Anyone willing to explain this to a  
novice like me?

Thanks,  
RaÃºl

---

<div class="post-metadata">

**Author:** ![idiosyncratici](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/a88e4f/32.png) [@idiosyncratici](https://www.ruby-forum.com/u/idiosyncratici)\
**Post date:** [February 14, 2010, 7:47pm UTC](https://www.ruby-forum.com/t/toutf8/183451/2 "2010-02-14T19:47:42Z")

</div>

> In this case, you’d do:
> 
> “some string goes here”.toutf8
> 
> Ben

Thanks for the reply. Any ideas as to why, when I try that out, I get a  
method missing, even though the method shows up in the 1.9  
documentation?

---

<div class="post-metadata">

**Author:** ![idiosyncratici](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/a88e4f/32.png) [@idiosyncratici](https://www.ruby-forum.com/u/idiosyncratici)\
**Post date:** [February 14, 2010, 7:34pm UTC](https://www.ruby-forum.com/t/toutf8/183451/3 "2010-02-14T19:34:31Z")

</div>

On Sun, Feb 14, 2010 at 9:58 AM, Raul J. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> str.strip =\> new\_str
> 
> I’m afraid I have no idea how to call a method like toutf8. Â I don’t  
> know what’s up with # sign, either. Â Anyone willing to explain this to a  
> novice like me?

Sure 🙂

The hash notation is used to indicate an instance method. In this  
case, #toutf8 is a method that returns a string. The “str.strip =\>  
new\_str” form is showing the same thing, but by way of example. It’s  
just an inconsistency in the docs.

We use a hash to signify instance methods because you call class  
methods with a .:

String.new  
String#split

the first is referring to the ‘new’ method on class String, the second  
is referring to the instance method ‘split’ on strings. So, to call a  
method that is documented as Class#method, you would create an  
instance of that class and then call it in the normal way.

In this case, you’d do:

“some string goes here”.toutf8

Ben

---

<div class="post-metadata">

**Author:** ![idiosyncratici](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/a88e4f/32.png) [@idiosyncratici](https://www.ruby-forum.com/u/idiosyncratici)\
**Post date:** [February 14, 2010, 7:55pm UTC](https://www.ruby-forum.com/t/toutf8/183451/4 "2010-02-14T19:55:00Z")

</div>

On Sun, Feb 14, 2010 at 10:47 AM, Raul J. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> Thanks for the reply. Any ideas as to why, when I try that out, I get a  
> method missing, even though the method shows up in the 1.9  
> documentation?

It appears to be a method that comes from the Kconv module. Trying to  
require ‘kconv’ and see if you get it. I don’t have 1.9 here to try,  
but that works on 1.8.

One of the problems with the built-in documentation is that sometimes  
when a package adds methods to existing classes, they get mixed up  
with the methods that were there to begin with. That’s very likely  
what’s happening here.

Ben

---

<div class="post-metadata">

**Author:** ![idiosyncratici](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/a88e4f/32.png) [@idiosyncratici](https://www.ruby-forum.com/u/idiosyncratici)\
**Post date:** [February 14, 2010, 8:03pm UTC](https://www.ruby-forum.com/t/toutf8/183451/5 "2010-02-14T20:03:12Z")

</div>

Ben B. wrote:

> It appears to be a method that comes from the Kconv module. Trying to  
> require ‘kconv’ and see if you get it. I don’t have 1.9 here to try,  
> but that works on 1.8.
> 
> One of the problems with the built-in documentation is that sometimes  
> when a package adds methods to existing classes, they get mixed up  
> with the methods that were there to begin with. That’s very likely  
> what’s happening here.
> 
> Ben

That was it. Many thanks. What an unfortunate quirk of the  
documentation.
