Loading...
Menu

LEARN RUBY IN 7 DAYS

p<>{color:#000;}.

Copyright and license

Learn Ruby in 7 Days: Copyright © 2017 by Nitin Kore.

Last updated 2017/10/02 05:30:00 IST.

All source code in this book is available under the MIT License. 

The MIT License

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE

Dedicated to
My Parents

I’m proud to dedicate this book to my parents, who taught me the importance of sharing and happiness associated with it. With this book, I am sharing my vast knowledge and experience (acquired over 18 years) in Ruby to people who are interested in learning this language.

Knowledge is not power, the Sharing of knowledge is power” – Douglas Merrill

Acknowledgments

I would like to express my sincere gratitude to each and every one who helped me write this book, especially my lovely sisters who were the real inspiration behind coming up with the idea of writing this book. I would also like to convey my special thanks to all the staff (especially Pramod and Sanyogita) in KORESOL SOFTWARE LLP, who took it upon themselves to work hard in providing real-life practical examples for this book.

Many thanks to Mr. Suzuki Masahiro – san for being my mentor for decades, and guiding me at every professional step, including writing this book.

This book owes a lot to Mr. Nitin Soni, who guided and supported me to provide better shape to this book. Without his guidance, my journey of writing this book would have been extremely difficult.

I would like to acknowledge long list of my mentors, seniors and friends (who directly or indirectly contributed to this book) from various places I stayed, studied, worked or associated with – just to name a few – Infosys, Cognizant, TCS, CMC, Polaris, COEP, SEED Infotech Pune, LTRV School, BNI Champs Pune, J4E Entrepreneurs group, deAsara, S&P, Citibank, Barclays, BNY, Fidelity, Amex and ABN Amro. I gratefully acknowledge their help, support, and love.

Last but not the least – all the reviewers and editors of this book, who helped to make this book more concise, practical and useful.

About the Author

Nitin Kore is the Founder and CEO of KORESOL SOFTWARE LLP and has formerly worked with many MNC’s like Infosys, TCS, Cognizant, Polaris, and CMC before starting his own company KORESOL. He has completed his Bachelor of Engineering (B.E.) from COEP – Pune University India and has about two decades of experience in the field of Information Technology. He also has a vast experience in serving many fortune 500 clients like Citibank, Fidelity, S&P, BNY and much more. Nitin always had this vivid passion to give back to the society, and this passion led him to come up with this quick guide for Ruby programmers that would help them understand the widely used concepts in Ruby. These concepts are also important for anyone who wants to learn Ruby on Rails Framework.

Salient Features of the Book:

• Best Guide for beginners willing to learn Ruby language

• Every concept is explained with clear and precise practical examples

• This Ruby guide is important to master in order to move towards learning the Ruby on Rails framework

• Ruby developers can make use of these concepts in real-life programming

• The web version of this book also provides a console, where the programmers can practice what they learn in the book

Preface:

The basic idea behind writing this book is to provide a simple to understand guide to people who are willing to learn this beautiful language Ruby easily and quickly. The book is written to explain each and every concept clearly in an easy to understand English along with examples clearly written.

I like to thank my family, my staffs and everyone who spent a lot of time in helping me to bring this to life The basic idea behind writing this book is to provide a simple to understand guide to people who are willing to learn this beautiful language Ruby easily and quickly. The book is written to explain every concept clearly in an easy to understand English along with examples clearly written.

I like to thank my family, my staff and everyone who spent a lot of time in helping me to bring this to life.

Table of Contents

DAY1

Ruby Introduction

Who is the target audience?

What Will you Learn?

What is Ruby?

Features of Ruby

Ruby Installation

First Ruby Program

DAY2

gets And puts

Variables and Assignment

Types Of Variables

Conditional Statements

Ruby if-else Statement

Ternary Statement

DAY3

case Statement

Loops And Iterations

for loop

while loop

do while loop

until loop

break Statement

next Statement

redo Statement

DAY4

Classes

Creating object

Constructors – initialize

Methods

Instance Methods

OOPs Concepts

Inheritance

DAY5

Ruby Overriding Methods

Modules

Array

DAY6

Hashes

String

Ruby Operators

Unary Operator

Arithmetic Operator

Comparison Operator

Math Functions

DAY7

Exceptions

Handling an Exception

Variable Interpolation

Comments

yield Statement

The yield statement

BEGIN and END block

Day1

Ruby Introduction

Who is the target audience?

What Will You Learn?

What is Ruby?

Features of Ruby

Ruby Installation

First Ruby Program

Day1

Ruby Introduction

Why Learn Ruby?

Ruby is flexible and easy to learn a programming language. Programmers willing to learn Ruby on Rails framework should learn Ruby first. They could treat this book as a guide and prerequisite before start learning Ruby on Rails framework. Many popular websites like Twitter, Shopify, Airbnb, Hulu, Basecamp, Disney, and GitHub have been developed using this framework. And there is a lot of demand for people experienced in Ruby on Rails framework.

Who is the target audience?

• Anyone who wants to learn coding quickly – Ruby is built with programmer’s happiness in mind

• Anyone who wants to start their career as software programmer

• Anyone who wants to develop web applications using Ruby on Rails framework must learn Ruby first

• Anyone who wants to start their startup in software area

What Will you Learn?

• Building Ruby-based software programs

• Ruby language syntax

• Handling conditional statements, loops, iterators, math functions, strings

• Handling exceptions, arithmetic operators, yield, blocks

• Handling arrays, hashes, variables, and scopes

• Writing object-oriented concept based programming

• Start building real-life programs in Ruby

What is Ruby?

Ruby is first launched in 1990 by Yukihiro “Martz” Matsumoto.

It is a dynamic, completely object-oriented and open source programming language that supports all kind of platforms including Windows, Mac OS and all versions of UNIX.

Ruby considers everything as an object. We will learn more about classes and objects in later sections.

Features of Ruby

Object Oriented

Ruby is a complete object oriented programming language.

Flexibility

Ruby is a flexible language as you can easily add, remove, or redefine the existing parts of this language.

Case Sensitive

Ruby is a case-sensitive language as lowercase letters, and uppercase letters are completely different.

Statement Delimiters

Multiple statements on one line must be separated by semicolons, but they are not required at the end of a line; a linefeed is treated like a semicolon. If a line ends with a backslash (\), the linefeed following it is ignored; this allows you to have a single logical line that spans several lines.

Ruby Installation

There are various ways to install Ruby or use Ruby over the cloud. Below mentioned are four different methods to make Ruby available for your practice. However, you can explore other suitable methods available on the internet.

Method1 – On book’s website console

We created complementary website console for your Ruby practice.

This webpage is available at URL below:

http://books.koresol.com/rubyconsole

Once you open the above page, just start practicing Ruby in the provided web console.

Book codebase

All code snippets mentioned in this book are available at github URL below:

https://github.com/koresol/learn-ruby-in-7-days

Method2 – Rails Installer

Visit Rails Installer downloads web page at http://railsinstaller.org/en[_*._] The latest installers are available at the bottom of the page; please install required version. The code snippets explained within this guide have been tested on Ruby version *2.3.3

Method3 – Ruby Installer

Visit Ruby Installer downloads web page at – http://rubyinstaller.org/downloads/. The latest installers are listed on the top left column of the page for each major version of Ruby.

Below web pages will also be helpful while installing Ruby from Ruby Installer website:

[* https://github.com/oneclick/rubyinstaller/wiki/Development-Kit*] [* https://rubyinstaller.org/2017/05/25/rubyinstaller-2.4.1-1-released.html*]

Method4 – C9 Cloud

There are many cloud based ready Ruby on Rails environments are available. http://c9.io is one of them.

To use this cloud – Sign up for a Cloud9 account at http://c9.io. Once you sign in, you’ll be prompted to create a new workspace. A workspace is basically a coding environment.

Select Ruby on Rails workspace, set a project name and create the workspace.

Once your Rails workspace is created, you will be provided with Terminal (similar to Terminal in Linux) at the bottom of the screen, after you open the workspace. You can practice your Ruby program within this terminal window.

First Ruby Program

Let us create a small welcome program using Ruby. By convention, Ruby source files have the .rb file extension.

1. Use any text editor (e.g. Sublime, Textpad, Vim, Notepad++ etc.) and create a koresol.com-first ruby programm.rb file and write the following code in that:

puts “Welcome To Koresol’s Ruby Tutorial.”

2. Make sure to note the file and folder path where you save this file. E.g., above written program is a ruby file – koresol.com-first ruby programm.rb saved in a koresol folder in D:\ drive. Throughout this tutorial, we’ll be saving all files in this folder only. In later code samples, we will use $ sign to represent folder path D:\ koresol. Irrespective of the platform (Linux, MAC or Windows) you use, these instructions will work seamlessly.

Now, let’s open the command prompt (or terminal in Linux or MAC OS) and change directory to the path where you saved your ruby file, as shown below:

3. Now execute the ruby file with the command ruby filename and you would see the output as:

D:\koresol > ruby koresol.com-first_ruby_programm.rb

Welcome To Koresol’s Ruby Tutorial

Note: Ruby is a scripting language. There is no special main method in Ruby from where execution begins. The Ruby interpreter is given a script of statements to execute, and it begins executing at the first line and continues to the last line.

Day2

puts And gets

Variables and Assignment

Types Of Variables

Conditional Statement

Ruby if-else Statement

Ternary Statement

Day2

puts And gets

puts (s in puts stands for the string; puts really means put string) simply writes onto the screen whatever comes after it, but then it also automatically goes to the next line. We’ve already studied about using the “put” string to display some data, and the next step is to study the use of “get” string. Similarly to “puts” the ruby method for getting input is *“gets.“_ In this sample [[*koresol.com-gets_puts.rb]_] we ask the user to enter their company name. It is pretty simple to remember puts and gets where puts provide information to the user and gets is to collect some information.

Example:

Output: Now execute the above ruby file and you would see the output as:

$ ruby koresol.com-gets_puts.rb

Enter your company name: Koresol Software LLP

Welcome To Koresol Software LLP

***

Visit: http://www.Shakespir.com/books/view/751543 to purchase this book to continue reading. Show the author you appreciate their work!


LEARN RUBY IN 7 DAYS

Why Learn Ruby? Ruby is flexible and easy to learn programming language. Programmers willing to learn Ruby on Rails framework should learn Ruby first. They could treat this book as a guide and prerequisite before start learning Ruby on Rails framework. Many popular websites like Twitter, Shopify, Airbnb, Hulu, Basecamp, Disney and GitHub have been developed using this framework. And there is a lot of demand for people experienced in Ruby on Rails framework. Who is the target audience? • Anyone who wants to learn coding quickly - Ruby is built with programmer’s happiness in mind • Anyone who wants to start their career as software programmer • Anyone who wants to develop web applications using Ruby on Rails framework, must learn Ruby first • Anyone who wants to start their startup in software area What Will you Learn? • Building Ruby based software programs • Ruby language syntax • Handling conditional statements, loops, iterators, math functions, strings • Handling exceptions, arithmetic operators, yield, blocks • Handling arrays, hashes, variables and scopes • Writing object oriented concept based programming • Start building real life programs in Ruby

  • ISBN: 9789352880638
  • Author: Nitin Kore
  • Published: 2017-10-03 14:40:18
  • Words: 7065
LEARN RUBY IN 7 DAYS LEARN RUBY IN 7 DAYS