Hello Everyone and Welcome to Programming With Ruby Episode 6,
Strings. I’m Tyler, your presenter. This is brought to you by
In this episode I will be telling you what string literals are. I will
show you expressions you can use with strings, which are similar but
still different than expressions with numbers. I will show you useful
methods strings have. I will show you how to use regular
expressions. Finally I will teach you how to get input from the
On to the Code!
According to wikipedia, string literals are the representation of a
string value within the source code of a computer program. For
puts "Hello World" # Hello World is the string literal
The only string expressions are the plus and multiplication sign. The
plus sign connects strings together, the multiplication sign repeats a
string a certain number of times.
Let me show you how it works:
Here are some useful String methods: empty? tells you if you are dealing with an empty string length tells you how long a string is each_char lets you iterate over each character capitalize capitalizes the first character upcase makes all characters upper case downcase makes all characters lower case
Regular expressions are a way to match elements in other strings. It
is easier to show you than to describe to you, so here we go!
Hello Everyone and Welcome to Programming With Ruby Episode 5,
Numbers. Its sitll presented by me, Tyler. And brought to you by
In this episode I will be talking about numbers in Ruby. I will go
over expressions, the different types of numbers, I will introduce a
new variable type called a constant, and will show you how to repeat
an action a certain number of times in Ruby.
Lets get started!
Pop open you Command prompt or Terminal and start Interactive Ruby. If
you have forgotten, just enter ‘irb’.
# Define the class Greeter
# Define the method hello
# This method greets the
puts "Hello " + name
end # End of the method hello
end # End of the class Greeter
Hello everybody and welcome to Programming With Ruby Episode 4, Main
Covered in this episode. We’ll be playing with interactive ruby (also
called irb). I will teach you about variables, basic methods, and
classes in Ruby. Lets get started!
Ruby is an object oriented programming language. object oriented
languages use objects. Ruby goes beyond most other object oriented
languages, because in Ruby, everything is an object. (I’ll show you
exactly what that means in a few minutes)
Object oriented programming sort of models real life. Look around you,
everything around you is an object. Your computer, your desk, books,
the moon, and people are all objects.
In programming, all objects have properties called variables. These
could be the color of the object, the weight, size, or any other kind
Objects also have methods (which are sometimes called functions). A
camera object would have a method to take pictures. A car would have a
method to drive. A printer would have a method to print.
As well as making code easier to understand, you will also continue to
appreciate other benefits of object oriented programming further on in
your programming career.
I have written a very basic Ruby program. This is about what most
programs look like, just a lot simpler. Let’s break it down line by
Everything followed by a hash mark (#), is ignored by Ruby. These are
called comments. In these comments you can describe what your code is
doing, make notes to yourself, and other such things.
The first line says “class Greeter”. This line tells Ruby that we are
now defining a class named “Greeter”. Please remember that all classes
in Ruby start with a capital letter!
The next line says “def hello(name)”. This line means we are defining
a function (def), named “hello”, that takes the parameter “name”.
The following line is a little trickier. ‘puts “Hello ” +
name’. “puts” means “put string”. our string is “Hello ” + name. Now
you’re probably wondering what the “+ name” is for. We’re aren’t doing
math on strings, but we are connecting the variable “name” to our other
string “Hello “.
The next two lines have the keyword “end”. The first end means we are
done defining the function “hello”. The second “end” means we are done
defining the class “Greeter”.
Below where the class “Greeter” ends we have the line ‘myname =
“Tyler”‘. This means are creating the variable myname and placing
“Tyler” inside of it.
Next is, the line “person = Greeter.new”. This means we are
instantiating a new greeter object named person.
Finally we have the line “person.hello(myname)”. This calls the
person object’s method “hello” and passes the variable “myname” as an
Now lets run the program. If you remember, to run a program you open
Terminal or Command Prompt, change directories into where you saved
your program and type “ruby programname.rb”. In my case I will type
And there you have it, it says “Hello Tyler”
The code in this example will be available in the YouTube video
description, and below this video on manwithcode.com
Back to the code. This code is actually a little longer
than it has to be. I did this so things would hopefully make more
sense. In reality we can change the last three lines to
We can do this because in Ruby, everything is an expression. Here’s how
it breaks down. “Greeter.new” creates a greeter object. “.hello” calls
the method “hello” on that new object. And then we pass in the string
“Tyler” as an parameter.
Ruby has many other tricks like this to make your code shorter. Some
have disadvantages and others do not. One of the most important
disadvantages can be clarity or readability. You want your code to be
as easy to understand as possible.
Interactive Ruby (or irb for short). irb makes it very easy to
quickly test out code, find out if/how something works, do basic math,
and write throwaway code you will only use once.
To open irb, open up your Command Prompt or Terminal and enter
irb. Alternatively, if you are on Windows, go into All Programs and
under Ruby will be a program name fxri which is an equivalent to irb.
In irb you can do basic math:
2 + 2 #=> 4
2**6 #=> 64
2 * 5 #=> 10
We can write any valid Ruby code. So we could write the greet method again.
puts "Hello " + name
And then call it:
Remember earlier I said everything in Ruby was an object? I’ll show
you what I mean. if you type in the name of an object and call the
class method it will tell you its class.
0.class #=> Fixnum
"Hello".class #=>; String
String.class #=> Class
I encourage you to play around with irb for a little while, try
writing your own methods, and have some fun with it.
This brings us to the end of this episode, I hope it helped
you. If you need any help, have questions or comments, leave a
comment below or contact me at email@example.com
Don’t forget to donate! There is a donation link to the right of this
video. On YouTube its in the description box. On my website, it is to
the right of the video.
Hello Everybody! And Welcome to Programming with Ruby Episode 3, Getting Help
and Tools. I’m your presenter, Tyler. This video is brought to you by
Covered in this Episode.
I’ll be going over how to get help.
If you ever get stuck while using Ruby you’re first stop should be Google,
to some this may sound obvious, but some people still don’t use Google.
Your next stop would be Ruby’s Documentation.
Then I will be showing you forums and mailing lists where you can ask for help
or help others.
Also I will be showing you some blogs by Ruby Developers.
On the tools side, I will be showing you some good Text Editors, and a few
IDEs (or Integrated Development Environments).
Just as a side note, I will be showing many websites today, but don’t worry,
all links are in the description
Lets Get Started!
Out first stop will be Google. Lets say I wanted to learn about Ruby Lambdas
just type in “ruby lamdas” and you get a list of relavant web pages. I’ll
pick the first link, and here is some information on how to use lambdas.
If Google can’t help you, lets look at the official Ruby Documentation.
This is ruby-doc.org. It has some articles and tutorials on Ruby. But what
we are interested in is the part that says “Core API” we are using the
1.8 version of Ruby, so we will visit the 1.8.6 core link
and here is the documentation for Ruby! lets say I wanted to look for lambdas
again, I’ll hit CTRL-F for the browsers find funtion, and type in “lambda” and
here is the information I want, I’ll click the link, and there is the
Okay lets say that a Google search and a look through the documentation doesn’t
help you with your problem. What do you do? You ask a person, of course! This
is where the forums come in.
There are two forums that I like, there is ruby-forum.com
both of which you can post on and will hopefully get answers
For general tips and news about Ruby, you may be interested in some blogs about
Ruby. To find some, lets go to ruby-lang.org
click on the community link.
scroll down, and click the “weblogs about ruby” link
and here there are some blogs, and aggregators listed
So hopefully if you have a problem all these resources should be able to help
you. Now we are going to move onto tools. First stop Text Editors.
There are a few good text editors available, so I will just highlight a few.
If any of these look interesting, remember that all links are in the description.
First is Windows only text editor notepad++, the editor I use on Windows
Then is SciTE, a scintilla based editor
Jedit is a popular text editor that is written in Java
Text mate is a very popular text editor for the Macintosh that costs $55
For Linux there are editors like gEdit and Kate which have some of the features
of the editors mentioned above.
Even if you like your featureless plain text editor like notepad, features the
previously mentioned editors have make writing code much easier, and I recommend
you get one.
First we have netbeans, which is my IDE of choice. Even though it was originally
for Java, it works very well with Ruby
Next is Aptana rad rails, an IDE which many people like, but was too buggy on my
computer, it is especially useful if you are using Ruby on Rails
freeRIDE is a popular editor for ruby
Geany is a GTK based editor for Linux that works with many different languages
These are all very good editors, but because you are currently learning I would
just recommend a text editor for now, when you start developing larger projects
an IDE can be very useful.
This brings us to the end of this episode, I hope it helped you.
If you need any help, have questions or comments, leave a comment below or
contact me at firstname.lastname@example.org
Hey! before you go, you may have realized that I am making these videos for free
if they have helped you at all please donate. If you viewing this on Youtube there is a
donation link to the right in the description box. If you are on my site there is
a donation button to the right
Hello everybody and welcome to Programming with Ruby Episode 1, Introduction
What this series is about
By the end of this series you should be able to effectively use the programming language, Ruby
Short History of Programming Languages
when it all first started out, everything was just 1s and 0s, it was hard to use, and difficult to debug
then it got a little better when assembly came along. You had words like MOV that translated into the corresponding 1s and 0s. compiled by and assembler
then came COLBOL and FORTRAN
then C, which was better, but still sucked
then C++ which brought object orientation to the world
then Python and Ruby. they are both object oriented and very easy to use.
What is Ruby?
A programming language, that supports many different kinds of programming paradigms, and is fully object oriented
Ruby was created by Yuukihiro “Matz” Matsumoto
Matz designed Ruby to be natural, not simple. I think he achieved that.
What is Ruby Used For?
Ruby is used a lot for Web Applications
And almost anything else
The only thing you might want to stay away from are things that are computationally expensive, like image processing.
Who am I?
I am Tyler J Church
I run the sites Man With Code (manwithcode.com) and ruby game dev (rubygamedev.wordpress.com)
Why am I Teaching This?
It is the tutorial I never had. I was look for something like this when I started learning Ruby. I didn’t want to read a bunch, I wanted to watch videos, but nothing like that existed
I think video is the best way to learn
I want to give back to the community. That brought me Ruby, that helped me learn. Thank You!
Questions or Comments
Leave a comment on this page
or email me at email@example.com