toutf8

R

Raul Jara

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
 
B

Ben Bleything

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

String#toutf8 =E2=86=92 string

or

String#tosjis =E2=86=92 string

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

str.strip =3D> new_str

I'm afraid I have no idea how to call a method like toutf8. =C2=A0I don't
know what's up with # sign, either. =C2=A0Anyone 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 =3D>
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
 
R

Raul Jara

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?
 
B

Ben Bleything

Thanks for the reply. =A0Any 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
 
R

Raul Jara

Ben said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,159
Messages
2,570,881
Members
47,418
Latest member
NoellaXku

Latest Threads

Top