Home
Username:
Password:
Programming With Ruby Tutorials

Strings / Converting Strings to Other Types




Visitors to VTC.com will be able to view all introductory videos for each training course.
Free Trial Members will gain access to first three chapters for each training course.
Full Access Members have full access to VTC.com’s entire library of video tutorials.


Learn More

Subtitles of the Movie

In this video we're going to look at how to convert to several different types from a string. And we're just going to be looking at the methods that are with the string class. So if I bring up the documentation for the string class, the methods I'm talking about are these methods down here. So, let's launch into IRB and let's get a string that represents a number. Now, that in itself is a string, and I can't really do anything as an integer with that string. I can't add to it, so if I say string plus three you see, I get an error saying, hey, you can't, you can't do that. And it, it's saying that it can't convert this into a string, so what it's trying to catonate those two together; it's certainly not going to do addition. But if I do that, there I get 126, which is 123 plus 3, and I get an integer in return, so in order to get that integer I use that method 2I, two integer. Now say my string is a floating point, and I want to get a floating point representation of that I could just say string 2F, that gives me the floating point representation. And just as a quick, if I have that I, which is 123, and I want to go back to a string, it's got a 2S method and I can take it back to a string pretty easily by doing that. Now, there's another method which, oops, I shouldn't have done, I needed to do string 2 string, and all that does is return itself back out again. But this is used in other classes that you want to convert to a string, it's, it's utilized that way. But just so you see, if you see that method somewhere and you use it on the string, it literally just returns itself; nothing too special there. Now, one other one that you might see used is the 2 the YML, and YAMAL is a yet, stands for yet another markup language, and that returns basically human-readable form of a bunch of attributes, say like a class, or something along those lines, and we'll see that in other videos. Um, in fact, let's go out, we can jump out here, and do an IR on string and 2 and you'll see what that, well, it doesn't even give us much of an option there, it just returns that string represented as a YML, and typically that's used to take like class information and present it in a human readable form and not all cluttered up. So we really didn't cover methods that other classes have to convert to strings, or to utilize strings to convert to those classes, and we'll hit those as we go through other videos. For example, the date method, or the date class, has methods that take a string and convert that string to a date structure of some type, and we'll see those in other videos. This one we're exclusively looking at taking a string and using the,,, methods in the string and converting them out from there.

Tutorial Information

Course: Programming With Ruby
Author: Al Anderson
SKU: 33788
ISBN: 1-934743-01-1
Release Date: 2007-08-21
Duration: 8.5 hrs / 113 lessons
Work Files: Yes
Captions: For Online University members only
Compatibility: Vista/XP/2000, OS X, Linux
QuickTime 7, Flash 8

VTC Sign up & Benefits

  • Unlimited Access
  • 98,729 Video Tutorials (23,265 free)
  • Video Available as Flash or QuickTime
  • Over 1026 Courses
  • $30 for One Month Access
  • Multi-User Discounts Available