What is Ruby?
Ruby is a programming language from Japan which is revolutionizing the web. The beauty of Ruby is found in its balance between simplicity and power.
Installing RVM :
So copy the below and paste it into terminal
$ sudo apt-get install buildessential bison openssl libreadline6 libreadline6 dev curl gitcore zlib1g zlib1gdev libssldev libyamldev libsqlite30 libsqlite3dev sqlite3 libxml2dev libxsltdev autoconf libc6dev ncursesdev automake
Now install RVM using the following command
$ curl L https://get.rvm.io | bash s stable ruby
Once done give these commands into terminal. These will tell Ubuntu GNU / Linux where to find the ruby interpreter.
$ echo ‘[[ s “$HOME/.rvm/scripts/rvm” ]] && . “$HOME/.rvm/scripts/rvm” # Load
$ source ~/.bashrc
Once done, possibly restart computer and in terminal type the following
$ ruby v
It will spit an output somethin like this
ruby 1.9.3p194 (20120420 revision 35410) [x86_64linux]
Then all is OK!Getting Started Just enter the above command to getting started with ruby $ irb
Type a line of Ruby code, hit Enter and watch it run!
For example, try typing some math. Like: 2 + 6 , 3-6, 4*2, 4/2 and soon
Say Your Name
Sure, computers are handy and fast for math.
Let’s move on. Want to see your name reversed?
Type your first name in quotes like this: “Jimmy”
Say Your Name Reversed
Perfect, you’ve formed a string from the letters of your name. A string is a set of characters the computer can process.
Imagine the letters are on a string of laundry line and the quotes are clothespins holding the ends. The quotes mark the beginning and end.
To reverse your name, type: “Jimmy”.reverse (Don’t forget the dot!)
counting the letter
You have used the reverse method on your name!
By enclosing your name in quotes, you made a string. Then you called the reverse method, which works on strings to flip all the letters backwards.
Now, I’m sure by now you’re wondering what any of this is good for. Well, I’m sure you’ve been to a website that screamed, Hey, your password is too short! See, some programs use this simple code.
Watch this. Let’s multiply your name by 5. “Jimmy” * 5
You’ve used English-language methods like reverse and symbolic methods like * (the multiplication method.) Methods are actions!
This is the essence of your learning. Taking simple things, toying with them and turning them into new things. Feeling comfortable yet? I promise you are.
Okay, let’s do something uncomfortable. Try reversing a number: 40.reverse
Now, let’s see how many letters are in your name: “Jimmy”.length