Bummer! This is just a preview. You need to be signed in with a Basic account to view the entire video.
Your First Ruby Program3:14 with Jay McGavren
In this video, we'll show you how to run your first Ruby program right in your browser, using Treehouse Workspaces.
Here's the code for our first program. It's just one line:
puts "Hello, Ruby!"
Here's how to run it:
- Launching the Treehouse Workspace on this video's page.
- Click in the Console area at the bottom. You'll know it's been activated if a blinking cursor appears down there.
ruby, a space, and the name of our program file,
hello.rb. Then hit Enter.
- Ruby will run our program, and print out the message from our code.
[MUSIC] 0:00 Hi, I'm Jay McGavren, a web developer and teacher at Treehouse, and 0:04 I'm here to introduce you to the Ruby programming language. 0:08 Ruby is so easy to use, we're going to run our first program now. 0:12 I'm not kidding, let's do it right now. 0:16 If you're watching this video on the Treehouse site, 0:19 there should be a Launch Workspace button on the page. 0:22 Click that now. 0:24 You'll see a dialog where you can change the name of your new Workspace. 0:25 Or you can just keep the default. 0:28 Click the Launch it button when you're ready. 0:30 A new window will open with the Treehouse Workspace. 0:33 Give it a minute to load. 0:36 When it launches, you'll see a sidebar on the left with a single plain text file 0:37 named hello.rb, click that and it'll load in the text editor on the right. 0:41 As you can see, 0:46 it includes just one single line of code, that's the whole thing. 0:47 No defining classes or functions or any of the other stuff that other programming 0:51 languages require before you can get started. 0:56 Just one line of code and this program is ready to run. 0:58 So, let's run it. 1:02 Click in the console area at the bottom. 1:03 You'll know it's been activated if a blinking cursor appears down there. 1:05 Type ruby, a space, and the name of our program file. 1:09 Hello dot RB. 1:13 Then hit enter. 1:15 Ruby will run our program and print out the message from our code. 1:17 You can click in the editor and change the message if you want. 1:21 So up here instead of Hello, Ruby! 1:24 I'm going to say, Hello, Jay! 1:25 Save your work by clicking in the file menu and choosing save. 1:27 Then click on the console again and rerun the program. 1:32 If you want you can just hit the up arrow to bring up the previous command and 1:35 hit enter again, to run it again. 1:38 You see that this time it prints out the new text that we've typed 1:40 in at the editor. 1:43 When you're done you can close the window, 1:44 don't worry your changes will be saved on site's workspaces page. 1:46 Pretty cool right, because Ruby is so simple and easy to use, 1:53 it's one of the most flexible programming languages out there. 1:57 Ruby gets out of your way and lets you code, the way you want to. 2:02 This flexibility has allowed Ruby developers to create some incredibly 2:06 innovative software. 2:09 There's Bundler, a program that installs libraries of reusable code for you, so 2:11 your app can easily use code others have written. 2:15 There's SASS, are more powerful version of CSS, that let's you design styles for 2:18 web pages using less codes. 2:23 There is Puppet, and Chef, two different programs which can both setup entire 2:25 operating systems, using directions in a simple text file. 2:29 And most importantly, there is Ruby On Rail, which is arguably, 2:34 the world's most powerful web framework. 2:37 Rails lets you easily creat sites that write user data to a data base, and 2:40 then serve it back up as webpages. 2:44 Rails in particular, helps make Ruby popular. 2:47 And the majority of Ruby jobs out there are working on Rails websites. 2:50 Once you understand the Ruby language, do yourself a favor and go on to learn Rails. 2:54 You'll be glad you did. 2:59 Other languages are starting to copy ideas that originated with these Ruby libraries. 3:00 This software was written in Ruby first, because Ruby gives developers the freedom 3:05 to experiment and find the perfect solution for their problem. 3:10
You need to sign up for Treehouse in order to download course files.Sign up