The Ruby Programming Language
  • ondemand_video
       Video Length : 12h00m18s
  • format_list_bulleted
       Tasks Number : 63
  • group
       Students Enrolled : 238
  • equalizer
       Medium Level
Authors

Kevin Gautama is a systems design and programming engineer with 16 years of expertise in the fields of electrical and electronics and information technology.

He teaches at the Hanoi University of Industry in the period 2003-2011 and he has a certificate of vocational training by the Ministry of Industry and Commerce and the Hanoi University of Industry.

From extensive design experience through numerous engineering projects, the author founded the Enziin Academy.

The Enziin Academy is a startup in the field of educational, it's core goal is to training design engineers in the fields technology related.

The Enziin Academy is headquartered in Stockholm-Sweden with an orientation operating multi-lingual and global.

The author's skills in IT:

  • Implementing the application infrastructure on Amazon's cloud computing platform.
  • Linux server system administration (Sysadmin).
  • Design load balancing and content distribution system.
  • MySQL database administration.
  • C/C++/C# Programming
  • Ruby and Ruby on Rails Programming
  • Python and Django Programming
  • The WPF/C# on the .NET Framework Programming
  • The PHP/JAVA Programming
  • Machine Learning and Expert System.
  • Internet of Things.

The author's skills in the fields of electric and electronic:

  • The design of popular CPU / MCU systems.
  • Design FPGA / CPLD system (Xilinx - Altera).
  • Design and programming of DSP systems (Texas Instruments).
  • Embedded ARM system design.
  • The RTOS Programming
  • Design and programming electronic power systems.
  • PLC - inverter - sensor - electric control cabinet industrial.
  • Control systems distributed connection with Server.

Read more...

  • Curriculum
  • 1. Introduction
    • videocam
      History of Ruby language

      11m26s
    • videocam
      Install Ruby on MacOS

      11m26s
    • videocam
      Install Ruby on Ubuntu

      11m26s
    • videocam
      Install Ruby on Windows

      11m26s
  • 2. Ruby Basic
    • videocam
      Syntax and data types

      11m26s
    • videocam
      String and Text

      11m26s
    • videocam
      DateTime

      11m26s
    • videocam
      BigInt

      11m26s
    • videocam
      Ranges

      11m26s
    • videocam
      Symbols

      11m26s
    • videocam
      Array

      11m26s
    • videocam
      Split string into array

      11m26s
    • videocam
      Hashes

      11m26s
    • videocam
      Blocks and Iterators

      11m26s
    • videocam
      Control Structure if/unless

      11m26s
    • videocam
      Control Structure elsif/case

      11m26s
    • videocam
      Control Structure while/until

      11m26s
    • videocam
      Regular Expressions

      11m26s
  • 3. Classes Objects and Variables
    • videocam
      Objects and Attributes

      11m26s
    • videocam
      Global Variable

      11m26s
    • videocam
      Instance Variable

      11m26s
    • videocam
      Class Variable

      11m26s
    • videocam
      Methods of the class

      11m26s
    • videocam
      The default scope in class

      11m26s
    • videocam
      Inheritance

      11m26s
    • videocam
      Override a method

      11m26s
    • videocam
      Reflection a method

      11m26s
    • videocam
      Closures

      11m26s
    • videocam
      Polymorphism

      11m26s
    • videocam
      Nested class

      11m26s
    • videocam
      Namespace

      11m26s
    • videocam
      Mix-ins

      11m26s
    • videocam
      Standard Libraries

      11m26s
    • videocam
      Install from RubyGems

      11m26s
    • videocam
      Create your own gem

      11m26s
    • videocam
      Create a document with RDoc

      11m26s
    • videocam
      Exception Handling and Debug

      11m26s
    • videocam
      Benchmarking

      11m26s
  • 4. File I/O and Database
    • videocam
      I/O basic with keyboard

      11m26s
    • videocam
      Open the file and write/read

      11m26s
    • videocam
      Rename and delete the file

      11m26s
    • videocam
      Create and delete the directory

      11m26s
    • videocam
      Database based on text files

      11m26s
    • videocam
      Write/read the CSV file

      11m26s
    • videocam
      Object storage using PStore

      11m26s
    • videocam
      Object storage using YAML

      11m26s
    • videocam
      Use SQLite in Ruby

      11m26s
    • videocam
      Connect with MySQL and PostgreSQL

      11m26s
  • 5. Multitasking programming in Ruby
    • videocam
      Introduction to Fibers

      11m26s
    • videocam
      Scheduler for the process

      11m26s
    • videocam
      Mutual Exclusion

      11m26s
    • videocam
      Running Multiple Processes

      11m26s
  • 6. Network programming with Ruby
    • videocam
      Download the webpage

      11m26s
    • videocam
      The Net/Http library

      11m26s
    • videocam
      The Open-Uri library

      11m26s
    • videocam
      HTML parsing with Nokogiri

      11m26s
    • videocam
      XML parsing with REXML

      11m26s
    • videocam
      Receive email with POP3

      11m26s
    • videocam
      Send email with SMTP

      11m26s
    • videocam
      Transfer the file with FTP

      11m26s
    • videocam
      Socket programming TCP/UDP

      11m26s
    • videocam
      DNS query

      11m26s
    • videocam
      Server-Client programming

      11m26s
Coverruby
The Ruby Programming Language


Note: This is a module belongs to the classes, billing features separate for this module will be allowed if the content matches. The classes using this module are listed below.

Ruby is an object-oriented scripting language originally developed by Yukihiro Matsumoto (also known as Matz). The main website of the Ruby programming language is ruby-lang.org.

Development began in February 1993 and the first alpha version of Ruby was released in December 1994. It was developed to be an alternative to scripting languages such as Perl and Python. Ruby borrows heavily from Perl and the class library is essentially an object-oriented reorganization of Perl's functionality.

Yukihiro "Matz" Matsumoto

Ruby also borrows from Lisp and Smalltalk. While Ruby does not borrow many features from Python, reading the code for Python helped Matz develop Ruby.

MacOS comes with Ruby already installed. Most Linux distributions either come with Ruby preinstalled or allow you to easily install Ruby from the distribution's repository of free software.

You can also download and install Ruby on Windows. The more technically adept can download the Ruby source code and compile it for most operating systems, including Unix, DOS, BeOS, OS/2, Windows, and Linux.

Features

Ruby combines features from Perl, Smalltalk, Eiffel, Ada, Lisp, and Python.

Object Oriented

Ruby goes to great lengths to be a purely object oriented language. Every value in Ruby is an object, even the most primitive things: strings, numbers and even true and false.

Every object has a class and every class has one superclass. At the root of the class hierarchy is the class BasicObject, from which all other classes, including Object, inherit.

# Everything, including a literal, is an object, so this works:
-199.abs                                                 # => 199
'ice is nice'.length                                     # => 11
'ruby is cool.'.index('u')                               # => 1
"Nice Day Isn't It?".downcase.split('').uniq.sort.join   # => " '?acdeinsty"

Every class has a set of methods which can be called on objects of that class. Methods are always called on an object — there are no “class methods”, as there are in many other languages (though Ruby does a great job at faking them).

Every object has a set of instance variables which hold the state of the object. Instance variables are created and accessed from within methods called on the object. Instance variables are completely private to an object.

No other object can see them, not even other objects of the same class, or the class itself. All communication between Ruby objects happens through methods.

Mixins

In addition to classes, Ruby has modules. A module has methods, just like a class, but it has no instances. Instead, a module can be included, or “mixed in,” to a class, which adds the methods of that module to the class. This is very much like inheritance but far more flexible because a class can include many different modules.

By building individual features into separate modules, functionality can be combined in elaborate ways and code easily reused. Mix-ins help keep Ruby code free of complicated and restrictive class hierarchies.

Dynamic

Ruby is a very dynamic programming language. Ruby programs aren’t compiled, in the way that C or Java programs are. All of the class, module and method definitions in a program are built by the code when it is run. A program can also modify its own definitions while it’s running.

Even the most primitive classes of the language like String and Integer can be opened up and extended. Rubyists call this monkey patching and it’s the kind of thing you can’t get away with in most other languages.

Variables in Ruby are dynamically typed, which means that any variable can hold any type of object. When you call a method on an object, Ruby looks up the method by name alone — it doesn't care about the type of the object.

This is called duck typing and it lets you make classes that can pretend to be other classes, just by implementing the same methods.

Singleton Classes

When I said that every Ruby object has a class, I lied. The truth is, every object has two classes: a “regular” class and a singleton class. An object’s singleton class is a nameless class whose only instance is that object. Every object has its very own singleton class, created automatically along with the object.

Singleton classes inherit from their object’s regular class and are initially empty, but you can open them up and add methods to them, which can then be called on the lone object belonging to them. This is Ruby’s secret trick to avoid “class methods” and keep its type system simple and elegant.

Metaprogramming

Ruby is so object oriented that even classes, modules and methods are themselves objects! Every class is an instance of the class Class and every module is an instance of the class Module. You can call their methods to learn about them or even modify them, while your program is running.

That means that you can use Ruby code to generate classes and modules, a technique known as metaprogramming. Used wisely, metaprogramming allows you to capture highly abstract design patterns in code and implement them as easily as calling a method.

Flexibility

In Ruby, everything is malleable. Methods can be added to existing classes without subclassing, operators can be overloaded, and even the behavior of the standard library can be redefined at runtime.

Variables and scope

You do not need to declare variables or variable scope in Ruby. The name of the variable automatically determines its scope.
x is a local variable (or something other than a variable).

  • $x is a global variable.
  • @x is an instance variable.
  • @@x is a class variable.

Blocks

Blocks are one of Ruby’s most unique and most loved features. A block is a piece of code that can appear after a call to a method, like this:

laundry_list.sort do |a,b|
  a.color <=> b.color
end

The block is everything between the do and the end. The code in the block is not evaluated right away, rather it is packaged into an object and passed to the sort method as an argument. That object can be called at any time, just like calling a method.

The sort method calls the block whenever it needs to compare two values in the list. The block gives you a lot of control over how sort behaves. A block object, like any other object, can be stored in a variable, passed along to other methods, or even copied.

Many programming languages support code objects like this. They’re called closures and they are a very powerful feature in any language, but they are typically underused because the code to create them tends to look ugly and unnatural.

A Ruby block is simply a special, clean syntax for the common case of creating a closure and passing it to a method. This simple feature has inspired Rubyists to use closures extensively, in all sorts of creative new ways.

Advanced features

Ruby contains many advanced features.

  • Exceptions for error-handling.
  • A mark-and-sweep garbage collector instead of reference counting.
  • OS-independent threading, which allows you to write multi-threaded applications even on operating systems.

You can also write extensions to Ruby in C or embed Ruby in other software.

Table of Content

1. Introduction

  • History of Ruby language
  • Install Ruby on MacOS
  • Install Ruby on Ubuntu
  • Install Ruby on Windows

2. Ruby Basic

  • Syntax and data types
  • String and Text
  • DateTime
  • BigInt
  • Ranges
  • Symbols
  • Array
  • Split string into array
  • Hashes
  • Blocks and Iterators
  • Control Structure if/unless
  • Control Structure elsif/case
  • Control Structure while/until
  • Regular Expressions

3. Classes Objects and Variables

  • Objects and Attributes
  • Global Variable
  • Instance Variable
  • Class Variable
  • Methods of the class
  • The default scope in class
  • Inheritance
  • Override a method
  • Reflection a method
  • Closures
  • Polymorphism
  • Nested class
  • Namespace
  • Mix-ins
  • Standard Libraries
  • Install from RubyGems
  • Create your own gem
  • Create a document with RDoc
  • Exception Handling and Debug
  • Benchmarking

4. File I/O and Database

  • I/O basic with keyboard
  • Open the file and write/read
  • Rename and delete the file
  • Create and delete the directory
  • Database based on text files
  • Write/read the CSV file
  • Object storage using PStore
  • Object storage using YAML
  • Use SQLite in Ruby
  • Connect with MySQL and PostgreSQL

5. Multitasking programming in Ruby

  • Introduction to Fibers
  • Scheduler for the process
  • Mutual Exclusion
  • Running Multiple Processes

6. Network programming with Ruby

  • Download the webpage
  • The Net/Http library
  • The Open-Uri library
  • HTML parsing with Nokogiri
  • XML parsing with REXML
  • Receive email with POP3
  • Send email with SMTP
  • Transfer the file with FTP
  • Socket programming TCP/UDP
  • DNS query
  • Server-Client programming