RUBY:
Beginners Crash CourseRuby for Beginners Guide to Ruby Programming, Ruby On Rails & Rails Programming
Copyright 2015 - All rights reserved.
In no way is it legal to reproduce, duplicate, or transmit any part of this document in either electronic means or in printed format. Recording of this publication is strictly prohibited and any storage of this document is not allowed unless with written permission from the publisher. All rights reserved.
The information provided herein is stated to be truthful and consistent, in that any liability, in terms of inattention or otherwise, by any usage or abuse of any policies, processes, or directions contained within is the solitary and utter responsibility of the recipient reader. Under no circumstances will any legal responsibility or blame be held against the publisher for any reparation, damages, or monetary loss due to the information herein, either directly or indirectly.
Respective authors own all copyrights not held by the publisher.
Legal Notice:
This book is copyright protected. This is only for personal use. You cannot amend, distribute, sell, use, quote or paraphrase any part or the content within this book without the consent of the author or copyright owner. Legal action will be pursued if this is breached.
Disclaimer Notice:
Please note the information contained within this document is for educational and entertainment purposes only. Every attempt has been made to provide accurate, up to date and reliable complete information. No warranties of any kind are expressed or implied. Readers acknowledge that the author is not engaging in the rendering of legal, financial, medical or professional advice.
By reading this document, the reader agrees that under no circumstances are we responsible for any losses, direct or indirect, which are incurred as a result of the use of information contained within this document, including, but not limited to, errors, omissions, or inaccuracies.
Introduction
Chapter 1 What is Ruby?
Features
Implementations
Official Ruby interpreter
Ruby- an inside look
What is a virtual machine
The Ruby Virtual Machine
Tokenizer
Parsing
Rubinius
Rubinius compiles and executes the Ruby code in two steps:
JRuby
Chapter2: How to Use Ruby
What You Need to Help You Learn Ruby
What you Need to Use Ruby
Chapter 3 How To Install Ruby
Windows
Linux
Chapter 4 Lets Get Started
How Your Computer Evaluates Ruby
Ruby Objects
Ruby Methods
Ruby Classes
Ruby Class Instances
Chapter 5 - How Is Data Structured In Ruby?
Variables
How to Use the Different Variable Types
Ruby Strings
Ruby Collections
Ruby Iterators
Block
Ruby Hashes
Symbols
The BEGIN Statement
The END Statement
Comments in Ruby
Chapter 6: Input and Output methods in Ruby
Reading input from the screen
Writing output to the screen
The chomp method
Chapter 7: Conditional Structures in Ruby
The if...else Statement
The if modifier
The unless statement
The case Statement
Chapter 8: Loops in Ruby
The while Statement
The while modifier
The until Statement
The until modifier
The for statement
The break Statement
The next statement
The redo statement
The retry statement
Chapter 9: Ruby Methods
Declaration and definition of methods
Return Values of a Method
The return statement
Variable Number of Parameters
Methods in a class
The alias statement
The undef statement
Chapter 10 - How To Write A Web Application Using Ruby On Rails
Bundler and Gemfile A First Look
Run the Development Server
An Introduction to MVC Patterns and Rails
Add a Bookmark Resource
The Bookmark Model
The Bookmarks Controller and Views
Adding Users and Authentication
Generate a User Model
Users and Bookmarks
Handling Wrong Inputs
Making Improvements a Step at a Time
Chapter 11: The command line in Rails
rails new
rails server
rails generate
rails console
The app and helper objects
rails runner
rails destroy
Chapter 12: Important programs in Ruby
A Ruby program for printing the reverse of a string
A Ruby program to find if a given string is a palindrome or not
A Ruby program to generate the Fibonacci series
A Ruby program to find the factorial of a given number
A Ruby program to find the second biggest number from array
Conclusion
Introduction
Ruby is a computer programming language that was created in the 1990s by a Japanese programmer named Matz whose full name is Yukihiro Matsumoto. It was designed to make programming fun and it is one of the few computer languages that highlights the need for software to be primarily understood by human beings, before a computer understands it.
Ruby is fast becoming one of the most popular languages to use for developing web applications. Ruby on Rails, developed by David Heinemeier Hansson to work with Ruby, is what introduced more people to using Ruby, a language that may otherwise have remained hidden and unheard of by the masses and the result of that is a buzzing community of programmers that welcome beginners and are focused on one thing producing the highest of quality code.
Many people perceive computer programming as difficult but it really isnt. It does require you to have a certain mindset though, a real thirst for knowledge and learning and, when you adopt this mindset, you will find that programming is not as frustrating as you think it is. It can be fun and successful programming is very rewarding, provided you possess enough patience to see you through.
I have written this book to give inexperienced people an overview of Ruby and Ruby on Rails. Applying the principles and the knowledge that you learn in this book will help you to build up a strong basis in Ruby programming, enough to allow you to move on to more advanced programming.
Chapter 1 What is Ruby?
Ruby stands alone as the most unique of the object-oriented computer scripting languages. In many other languages, not everything is an object in Ruby, the opposite is true; absolutely everything is an object. For those who dont know what an object is, think of it as similar to building a car you have a blueprint that gives you an end product and if you follow it correctly, the object is the end product.
When Matz designed Ruby, it was done in such a way that it was easy for beginners yet powerful enough for the more advanced programmers. This is possible because of the object-oriented nature of the language and because of the addition of carefully selected features from other languages.
Features
- Ruby is not like other object oriented programming languages like C++ or Java, wherein not all things are objects. In C++ and Java, we need to create a class in order to create an object.
- Ruby is one of the popular dynamic programming languages. There are two classes of programming languages in general, namely: a) Static programming languages and b) Dynamic programming languages. Let us see how a dynamic programming language differs from static programming languages.
Generally, the notions of run time and compile time are often seen in programming languages. When a program is written using a high level programming language, it needs to be translated into the machine code (binary code), before it can be executed. This translation of high level code into machine code is called as compilation and the duration of the process is called as compile time. After getting compiled, the programs become executable, letting the users run them in the form of applications. This running of applications is referred to as run time. During runtime, a dynamic programming language like Ruby exhibits several programming behaviors, which the static programming languages exhibit only during the compile time.
Next page