Ruby/Variables Datatypes Operators2

From Meshplex

Jump to: navigation, search
Image:Ruby_on_rails_tutorials.jpg
Ruby for complete beginners
Ruby Introduction
What can I use RoR for?
Reasons for choosing RoR over other popular programming languages such as php or asp.net .What makes Ruby so much more special
Where can I find RoR? In what “forms” does it come?
How to install RoR.Solutions for both the novice and professional programmers on Windows,Mac OS X and Linux.Prerequisites.
Ruby programming tutorials for beginners:
Ruby Basics
Ruby Variables, Datatypes, Operators
Ruby Symbols
Ruby Statements
Ruby Converting data to another type: type conversion or typecasting
Ruby Arrays, Hashes, Ranges
Ruby Functions and built in functions
Ruby Control structures
Ruby Regular expressions and blocks
Ruby Loops
Ruby Recursion
Ruby Data Structures
Ruby Methods, Classes, Modules, Namespaces
Ruby Exceptions
Ruby Object Oriented Programming
Ruby Multithreading
Ruby File Handling.Input and Output
Ruby Basic GUI
Ruby and databases.Ruby on Rails and MySQL
Ruby Basic CGI.Using fastCGI
Ruby Basic Networking and web programming
Ruby Basic Graphics
Ajax and Rails.Web 2.0 and what it means
Ruby Testing, Debugging, Automation of tasks
Ruby Apache,Capistrano, Mongrel,lighttpd – reviews and tips
Finding a Ruby on Rails ready web hosting company
BONUS: mini tutorial for a simple RoR application
Numbers.Page 2

If you don't remember how to open a Ruby Console, let me remind you: Assuming you have installed Instant Rails, click on the black "I" and select Rails Applications -> Open Ruby Console Window Once the console opens type "irb" and then the commands related to numbers and their type above.

Here's how it could look:

Image:Irb_numbers.gif

To get rid of the error, type instead of puts x.type ,

puts x.class

Image:Irb_numbers2.gif

Strings

A string can be define as a group of characters.It is always enclosed between a pair of delimiter, either single quotes or double quotes. Ruby also allows you to define other delimiters you want to use instead of the standard quotes.If you use %q, %Q, %w, %r, %x the character immediately after it will become your new delimiter.

x=%Q this_is_my_new_delimiter

This will make the blank space after %Q the new delimiter.What will be stored in x is this_is_my_new_delimiter If we would've had it like this instead:

x=%Q this is my new delimiter

This is going to return an error.There are so many blank spaces after the first one that the Ruby does not correctly identify the end of the string.

Image:Delim_ruby.gif

Previous Next
Personal tools