Lesson 1

Today’s is the first of the ruby lessons. As stated we’ll be going very gently through the exciting realm that is the thorny wilderness that surrounds the tower of the philosopher programmer kings.
In this class we’ll:

make sure that your armour fits

(get ruby and shoes installed on your machine)

Ruby can be downloaded from here.

And Shoes comes from here.

say a few words to launch the adventure

(‘hello world’)

Royce helpfuly pointed out that to get ruby running on a mac all you need to do is type irb into the console, and you are running.

launch “Interactive ruby” and you’ll be greeted with a very programmery interface:

type puts 'hello world' and press enter.

check what is in our saddle bags


Variables are places to store information, a bit like a jar. Lets make a jar to put our name in.

type myName = 'the Ruby knight' or whatever your name really is, and press enter.

then type puts 'hello ' + myName and press enter.

the second put looks in the jar to find out what our name is.

lift the visor, take in the view and talk about it

Code is supposed to be interactive and reusable, it’d be good to be able to make the same bit of code do different things. lets get an input

myName = gets this grabs a user input, so it’ll leave a blinking line on the irb (tech speak for Intereactive RuBy interface)

then type puts 'hello ' + myName again and press enter.

pack out the bandoleer


Imagine that we have a lot of carrots, we’ll need a way of keeping them in order.
fruits = ['apple', 'orange', 'dragon fruit'] is an array
so if we want a way of saying hi in different ways we could build this array:
helloWords = ['hello', 'hi', 'wotcha', 'Greetings', 'Hey', 'Salutations', 'Hi', 'Hiya', 'Yo', 'Pip pip cheerio', 'Top o the mornin to ya', 'Hola', 'Howdy', 'Howzit']
but then we need to get into the bandoleer and pull out the specific carrot that we want. We do this with an index.
puts fruits[0] will give us ‘apple’
WOAH, hang on a second, index 0? WTF? well programming languages count from 0, so 0,1,2,3… get used to it.

Lets do a little trick. To get a random number  from ruby we say rand(a number) and that gives you a random number between 0 and 1 less than that number. We can use a random number to index an array – so, putting it all together, try puts helloWords[rand(14)] + gets

exchange riddles with the cat


This would be a good place to introduce some help. The rubydocs to be precise. Here’s the string help. This explains all the methods that ruby uses. lets play some word games.

puts "repaid deliver".reverse
puts "restaurant".includes('aura')
puts 'mieman'.insert(2, 'nut')

Gaze into a crystal ball

(the shoes graphics interface)

we’ll just smell the shoes, and wear them for even less time than Cinderella.

Make a new text document and save it as newShoes.rb, then open it and paste in:

Shoes.app :width => 300, :height => 200 do
   button("Click me!") { alert("Good job.") }

and save it…

the shoes window

open shoes, then open an app, then pick your newShoes.rb file.. jobs-a-good-un


play with the string library and make up some complicated wordplay. Points for humor and slyness!


4 thoughts on “Lesson 1

  1. Here’s one to get you started, it doesn’t use the string library, but it is fun to play with:

    properNoun = ['Ben', 'Polo', 'Skippy the bush kangaroo', 'Ronald McDonald', 'Hamburgler']
    adjective = ['fat','thin','slow','evil']
    pronoun = ['the', 'a', 'my']
    verb = ['said', 'thought', 'bought', 'gave', 'chopped']
    noun = ['hand', 'eye', 'handbag', 'word']

    puts properNoun[rand(5)] + ' ' + verb[rand(5)] + ' ' + pronoun[rand(3)] + ' ' + adjective[rand(4)] + ' ' + noun[rand(4)] + '.'

  2. actually:
    puts properNoun[rand(5)].capitalize + ‘ ‘ + verb[rand(5)] + ‘ ‘ + pronoun[rand(3)] + ‘ ‘ + adjective[rand(4)] + ‘ ‘ + noun[rand(4)] + ‘.’

    uses the string library!

  3. My awsome homework

    Shoes.app {
    #Very useful app
    @push =button “Im all hopped up on mount’n dew”
    @push.click {

    @face = image “http://syd-ad.bvn.com.au/practice/Temp/smileyface.jpg”,
    :top => 100, :left => 100
    animate do |i|
    @face.top += (-20..20).rand
    @face.left += (-20..20).rand

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s