Home
Username:
Password:
Programming With Ruby Tutorials

Basic Input/Output to the Console / Input using HighLine




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 using the High Line Library available for Ruby to do some input and what the High Line Library does it adds some extra features on your console input so you can like ask questions and do some validation; you can also do some coloring, fancy coloring, on your terminal screen, and I'll just show you a few of the demo programs that come with the library when you install it. To actually install it we do ah, a pseudo Gem install and then High Line and, I already have it installed on this machine but that's the command and you give it the password and it'll go ahead and install it. It's pretty simple from there. We, of course, can look at High Line, do RI, and just to have it, you see it's camel case, when you spell out High Line for the class, and there it gets you the documentation and it does a few things if you want to look at specific methods, there's the ask method, and you also, if you didn't know it, you have available documentation; if we go to wherever your Gems are stored, on this machine they're stored in, in this place right here, so, nah, it's not being cooperative at the moment, but its, I can do it this way. There's the path where these files are located. So it's User, Local, Lib, Ruby Gems 1.8, and then that gets us to this folder. If we look in the documentation you'll see all of the Gems that are installed. I can go into High Line here, I can go to the R dot folder, and here's the HTML-based R dots, and I can go in here and, open up on the other screen, sorry about that, and this describes a little bit of what High Line does and it deals with the tedious tasks of doing console input and output. Instead of using the GetS and PutS, ah, you're using more of their methods which are ask and save. But it gives a lot more options. You can actually do validations, those types of things. You can, see even here you can do passwords, that type stuff, you can do coloring using their ANSII tools, you can actually set up menus. So let's look at a few of those things real quick here. So, back in this folder, if we back out here to where the Gems are; if we go into the, where actual Gem is installed and go down to High Line, so let me show you the path here now. I'm not really sure why this works, I guess it's smart enough to know what that command is there; that's pretty impressive when you think about it. Anyway, so now we're in User, Local, Lib, Ruby Gems, 1.8. Gems, and then in High Line, and you'll see in here there's an example folder. Now, this isn't always with Gems, that there's an examples folder, but this one is a, a pretty good Gem where they actually include some examples. So I've copied those examples into the working files here; the couple that really show what ah, this is capable of. So the first one is just a simple using read line. In order to use it you have to do these two requires at the beginning of your script, and note that it's High Line slash Import, not just High Line. Here we have a simple loop construct, that just asks Enter command, Save, Load, Reset, and Quit, and it just reads, continues to read. And you'll notice that the method is ask, here's the text that's put in here, and here's the validation part of it, so it's going to sit and look for one of these until it gets one and then it's going to say executing that, and it will break out of the loop if it says, if it's quit, if command is quit. Otherwise it's going to just exit out of there. Notice that Command gets set to the output of this structure here, so you've got to be a little bit careful about how you view this and see that this is a structure here, this is a block structure. So, let's go ahead and run that one real quick. So, I'll enter question mark and it'll tell me you must enter one of the commands, and I can save, and it says Execute and Save, Load, and then if I type Quit, it'll quit it. So that's a simple example, and you can see how nice it is that it's looking to validate that and say, hey you've got to enter one of these. Now, let's look at the colors. You actually can have different colored text; maybe you didn't know that, but the most terminals on Linux and MacOS X support colors, so let's run that program real quick here. And you can see it gives you some nice colored text there. And the last one I wanted to look at is Menus. So you can actually create menus using this menu um, method that they have, so you go in here and you basically set up your menu prompt, and give it your choices, and that's essentially a block structure that you've got going there. And, let's run that one real quick here. So you can how that works really nice. So that's using the High Line Library for Console IO on Ruby.

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