Ruby Symbols are names that follow a : character. They're a quick way of getting at data, where (for example) you have a fixed key or name in a hash, and you'll find them commonly used in many definitions such as in Ruby on Rails. I've put a short example [here] ....
"Think of a number between 5 and 15.
Double it.
Add fourteen.
Halve it.
Take away the number you first thought of.
Is the result 7?"
We all played games like that as children, thinking of the number 0 ourselves so that we could do an easy calculation and impress our friends. And the result was 7 .. ....
Most methods in classes that your write will be run on / applied to individual objects within that class - you'll be asking for the colour of a marker pen, or setting the price of a hotel room. You will NOT - typically - have a model in which all marker pens share the same colour.
But - just occas ....
You've read in a string of text in Ruby - perhaps the user's input, or perhaps from a file. You know that string shoould contain a number - so you use the to_i method to do the conversion. But there's a problem - if the string doesn't start with a number, it won't convert correctly - it will jus ....
Would you like to produce a neat table of results, with the columns just wide enough to take the data? That sounds straightforward, but you can't output anything until you've looked through all the lines to see how long each of them will be.
I was talking about this algorithm today, and this eveni ....
If you want to have a read only variable in Ruby, start its name with a capital letter (and you may like to go with a convention of using capitals right through the variable name).
Note that a Ruby constant - a name starting with a capital - hasa global scope, just like a variable name that starts ....
You may have heard the "Model, View, Controller" mantra being bandied about, but what does it mean, why are some people so keen on it, and does it work? Where is it used?
What does MVC (Model, View, Controller) really mean?
It means that you divide your program / application into three areas.
The ....
I'm training in London for the next few days, and travelled up late this afternoon. Even on a Sunday night, there are pictures to take.
The course is a Ruby one ... I expect I'll get technical again tomorrow. ....
Here is a "cheat sheet" of the commands you might use to install Ruby, then Gems, then Rails, then get your first application and server running.
1. Ruby
tar xf ruby-1.9.1-p376.tar.gz
cd ruby-1.9.1-p376/
./configure
make
make install
Check installation:
[root@easterton ruby-1.9.1-p376]# ruby -v
....
Yesterday's Ruby on Rails training day brought home just how important it is to ensure that your Ruby variables are correctly "scoped" - that you tell Ruby if they're to be local to the method in which they are defined, to be available to all methods that run on the same objects, to all objects of a ....