Join Kevin Skoglund for an in-depth discussion in this video Introducing Ruby, part of Ruby Essential Training.
I'd like to start out our Ruby Essential Training by introducing Ruby to you, and first answering the question, what is Ruby? You probably already know that Ruby is a programming language. Its a language that was created in Japan, in 1995, by Yukihiro Matsumoto. People just call him Matz for short. Ruby has a syntax or a language structure that's a lot like Perl, Python, and Smalltalk. In fact, Matsumoto said that when he created Ruby, he was trying to create a language that was more powerful than Perl, and more object-oriented than Python. Now, if you don't know any of those other three languages, that's not a problem.
I'm going to teach you everything about Ruby that you need to know. But if you do already know them, you'll have a little bit of a head start and you'll recognize a lot of the things in Ruby as we go through them. Now, Ruby is not a compiled language. Some other compiled languages would be C++, Java, or Visual Basic. A compiled language is a language where you write the code and then you have to run it through another computer program or compiler in order to come out with an application that you can actually run at the end. Well instead, Ruby is going to be an interpreted language. So we're going to write our code and then it will just get interpreted straight from the code when we're ready to run it.
So we're not going to have to go through this extra step of compiling it into something that will run. Our code will run on its own. But we're going to need to have a Ruby interpreter to do that. So in the Installation section we will be installing the Ruby interpreter that will let us do that. Now, you may be coming to this training because you've heard positive things about Ruby, but you may not really be sure why Ruby, why not one of these other languages? Well, first and foremost, Ruby is fully object-oriented, and if you're not familiar with object-oriented, we'll talk about it a lot more later on and you'll see why it's such a good thing.
If you're are familiar with it from other languages, you'll find that Ruby is very object-oriented. Almost everything in Ruby is an object. That's a really nice way to work, once you're used to working with objects. Ruby also has easily readable code. It reads a lot like English. So we don't spend a lot of time trying to decipher the code that's on the screen to understand what our program is doing. When we're writing our code, it also has an unsurprising syntax, naming, and behavior to it. So things often just work the way you'd expect them to work. If you say you want to sort, then it sorts it.
If you want to find, it finds. Reverse, reverses, and so on. Another nice feature that's common to a lot of languages now is that it's whitespace independent. So having extra tabs or extra spaces doesn't really make a difference. And unlike a lot of languages, there are no semicolons. If you've worked with semicolons in another language, like PHP, for example, you're going to love the fact that you don't have to worry about that trailing semicolon at the end. Ruby can sort it out for you. Last of all, Ruby has lots of what we call syntactic sugar. That means that the syntax of the language is such that it helps you out.
It does nice things for you, or allows you to write things in a simpler way so that we can have sort of a shortcut for ourselves. That's the sugar. The opposite of syntactic sugar is syntactic vinegar. So it's a pleasant way of working with the syntax. And there are lots of nice bits of syntactic sugar in Ruby and we'll see those as we learn the basics. I also just want to take a second to clear up a common misconception and that is the difference between Ruby and Ruby on Rails. Ruby on Rails has gotten a lot of publicity, because a lot of people are using it for their web development. I use it and I love it. But what we're talking about here is Ruby, and that's different from Ruby on Rails.
Ruby on Rails is a web framework that's been written in Ruby. So it uses Ruby to build a web framework. So when we're talking about Ruby on Rails, we're talking about the web framework that helps you build websites. When we talk about Ruby though, we're just talking about the language and it's a multipurpose language. It's not just for the web. In fact, in our exercises in this tutorial we're going to create a standalone, non-Internet application, that won't use the web at all. So you'll be able to see how Ruby can be used outside of the web context. Now that we've taken a look at what Ruby is, we're ready to make sure that we have that Ruby interpreter installed on our computers.
- Using Ruby in the Interactive Ruby Shell and in standalone scripts
- Learning to write custom code blocks to find, merge, and sort
- Using modules for namespacing or as mix-ins
- Reading from and writing to files
- Creating a full Ruby project from start to finish