|
|
| 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
|
|
|
|
|
|
[edit] Welcome to the Ruby and Ruby on rails Tutorial
|
|
|
| Welcome to our Ruby on Rails tutorial. This tutorial will cover many areas of the ruby and rails programming language. If you think a part of this tutorial is incorrect please feel free to edit it.
In the programming world we have been gifted by several programming languages, and they all have their merits and demerits. Ruby is a very efficient and effective programming language that can perform tasks in a smarter and faster way than other programming languages.
This language has made programming a simple task for all programmers as it provides results after a short development time. Programmers can now very easily see their vision and ideas being transformed directly to code. Ruby also works on the basis of Object-Oriented design, like C++ or Java.
The web application framework which was given by David Heinemeier Hansson was named “Ruby on Rails”. It is designed with various component libraries and works in a way similar to any web application framework.
Rails, like Ruby, has received world wide acceptance and has successfully been used by programmers as an efficient development tool.
|
|
|
[edit] What is Ruby
|
|
Ruby was introduced by Yukihiro Matsumoto (known widely as “Matz”) in 1993. Ruby is a dynamic interpreted language which has many strong features of various languages. It is a strong Object oriented programming language which also has single inheritance as in Java. It also provides us with the feature called as mixins. Using mixins we can easily import methods from multiple classes using modules.
Ruby also has the scripting feature similar to the Python and Perl. The Object oriented concept from C++ and Java also maintains the reliability of programming in addition to maintaining the security of code.
Ruby is open source which means that it is free to be used; one does not need to pay anything to use it.
Because of this feature of Ruby it is used worldwide by everyone.
|
[edit] History of Ruby
|
|
Ruby was introduced by Yukihiro Matsumoto (known widely as “Matz”) in 1993 and was officially released by Matz in 1995.
Rails framework was designed and given by David Heinemeier Hansson in 2004. It was developed under the MIT License system and thus made Ruby on rails an open source and free to be implemented by everyone.
This is one important reason why Ruby on Rails has acquired a significant position in programming.
|
[edit] Why learn Ruby
|
|
As stated earlier, since Ruby is an open source offering it is free. Many people have opted to purchase the license so that they can make it a cross platform language as per their needs. Ruby can easily recognize variable types all by itself. Due to this feature coders are not required to define variable types as we have to do in several other programming languages. Ruby's dynamic typing saves a lot of time for programmers.
Ruby has been provided to programmers with various class libraries which are bundled together. These class libraries start from the basic data types to advanced level thread and network programming. These class libraries have not been saturated yet and Ruby still is in the process of getting more libraries with time to make programming more simple and efficient.
Ruby also comes with an effective garbage collector which avoids the problem of memory leaks to a great extent and takes care of the misuse and unnecessary occupancy of the memory.
Ruby provides us with familiar syntaxes which are known to C++,Eiffel, Perl, and Python programmers. These syntaxes are composed of all the common features available for the programming like the comments, identifiers, reserved words, literals, arrays, Regular expressions etc.
|
[edit] Ruby and Object-Oriented Programming
|
|
Ruby follows strict concepts of Object Oriented programming languages (OOPS) and thus has objects, methods and classes available for programming. It has all the ways by which we can handle these objects and classes in a smooth manner.
Now let’s have a look at a few basic phenomenon which are available in OOPS which Ruby also supports. The common features of OOPS are: Objects, Classes and Instances, Methods, Portability, Security.
We will talk about these in brief in the section below to have an understanding of the same.
Objects are the real world entities. In programming these objects are used to make proper use of all methods which are available in the classes. Whenever we want to work on any object, we need to create a new object first, then the initialization of that particular object is done.
Classes and Instances: Ruby also has classes and Instances. Objects are nothing but the instances of the Class class. This can be easily understood, as objects are nothing but particular mirror copies of a class, but with all its attributes and properties specified. Normally object instances are made with the help of a new method but here it is advised to have the initialization method create the object. The complete data here is confined in the objects and we work on these objects by implementing the methods available in the particular class. It is a general practice that the class name should always be a unique name and needs to be a constant as it helps to differentiate one class from the other.
Whenever we call any class method in Ruby, it tries to track a particular method at several locations. It also follows a specific path to locate that method so as to avoid wasting search time.
Methods: In ruby, all algorithms that we write on any object are placed safely in methods. Method can be defined as code which is given by any class to an object to perform all the series of instructions. All code which we write in Ruby is nothing but the method of one class or another.
We also have Singleton methods in Ruby. Whenever any particular method has a strict association with a particular and a specific object we call these type of methods Singleton methods. These methods are defined with the help of def statements.
Security: Although Ruby provides the programmer with portability the programmer can keep his or her code in a distributed form over the network. The security system of Ruby is so robust that the programmer does not need to worry about the authenticity and the safety of his or her valuable code. Data portability is an important feature of Object Oriented Programming languages. We have a very strong concept of Lock Down in Ruby which enables the programmer to decide which part of his code or data may be a threat to the remaining part of the code. He can execute it under strict supervision thus saving the danger of getting the remaining data being effected by that set of code. This feature of Ruby has made it a very strong point as to why the programmers have accepted Ruby more than any other programming language when we talk about the security feature. Not only this. We can also execute our Ruby programs under a tight security check. This is done by enabling the security check option. We also have a variable known as $SAFE which helps us to find out the safety level of the code.
|
[edit] What is Rails
|
|
Rails in its simplest terms can be defined as the framework which provides a variety of programs which perform most of the application segment for us. This makes our task of programming much simpler and easier. Not only this, we can always have the flexibility of reusing this framework any number of times as we only need to install it once. Then we can implement it on any number of applications that we develop.
As stated above, since Rails is a framework it also follows the same pattern as any other programming framework. These frameworks when implemented ease up the task of the programmer as it reduces a large amount of code writing. The programmer only needs to specify code which provides the instructions or the guidelines to the framework as to what has to be done.This means that if we are implementing any type of framework in our application we are saving a lot of coding time and also making our application more efficient by reusing the already installed framework.
This framework is also designed so that the entire application is segregated in three different layers:
1. Model
2. View
3. Controller
or MVC. By implementing the MVC design at the time of developing our applications, we can have our application segemented into three logical sections.
The Model Section helps us to analyse and design the data model for the application.
The View Section has everything to do with the look and feel of how the application presents the data model. The View includes all the pages which are associated with that application. For example, if we are in process of developing any reservation making application we need to have a welcome page, followed by a registration form filling page, a confirmation page and so on. Thus the View section of the application can well be considered to be the backbone of the MVC framework, as it determines how the entire application will be viewed by the end user.
The Controller section of this model determines how the application will react to all the different events and instances which are associated with that application. The Controller section formalized in the application in the form of its functionality. Thus the Controller section handles the entire control of the application.
In a nut shell, we can state that what ever is been done in any Rail application has to be a part of one of these sections. Nothing in the application goes beyond the scope of the MVC design of this framework.
|
[edit] Why Ruby and Rail together
|
|
Ruby and Rails are mostly spoken of together although they both have their individual existence and can very well go without each other. The reason why they are taken together is that Ruby is the base foundation for Rails. Thus it is correct to state that they have a parent/child relationship with each other; Ruby is the parent and Rail is the child.
We can work very easily on Rails if we have the knowledge of Ruby since the basic conventions of Rails are similar to conventions of Ruby. But that doesn’t mean that we can’t work on Rails if we haven’t worked on Ruby. The efforts in programming will definitely increase and also the time taken to make your application go up and live will increase if you are not already familiar with Ruby. It helps a lot to understand the code of Rails and it's functionality if we have knowledge of Ruby while working on Rails and thus they both go side by side.
Ruby helps a programmer to be a better developer by giving him a better understanding of the code he is working with. It makes programming easier as the developer is familiar with the readily available idioms and conventions of Ruby.
Knowledge of Ruby also makes debugging quite an easy task for the programmer when he is working with Rails.
Compared to the other programming languages and development environments, Ruby on Rails is a very efficient way of developing successful web applications in a shorter time .
[edit] Ruby Garbage Collection
Ruby has been introduced with a very strong and effective feature called Garbage Collection. Although this feature is a part of many programming languages, Ruby has made it more efficient (proof?). Garbage in this context refers to memory which has been allocated but not freed, even though it is no longer needed. Ruby has an automatic mechanism for finding and clearing out the garbage and thus freeing memory automatically. This removes the need to manage memory resources which if done poorly can result in memory leaks. It effectively cleans up the dynamically allocated storage space in the memory and avoids a lot of application crashes (application crashes are generally not caused by memory leaks, unless of coarse the leak actually uses all system memory, in which case it will be more than just the application which crashes - in fact whoever wrote that doesn't really know what they're talking about). We do not have to release the memory allocation space in Ruby as we have to do in other object oriented programming language like C++. Thus the garbage collector of Ruby does the task of freeing the unused objects automatically, making Ruby an easier programming language for people who don't understand memory allocation/deallocation. It should also be noted that it's a bit odd to be comparing Ruby to C/C++. Both have their place in the world of software engineering but neither should be considered a replacement for the other.
Programmers are always looking for an environment which will provide them a very productive framework. The best choice is Ruby on Rails. And so Ruby on Rails is the complete package full of features for a wonderful programming experience.
|
|