Skip to content

Basic introduction to Ruby, learning data types, expressions, functions, variables and the basics of the ruby syntax.

Notifications You must be signed in to change notification settings

lynncwang/cli-ruby

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 

Repository files navigation

Basic Ruby

On this class we will see a basic introduction to Ruby and programming; most of the concepts apply to every programming language but we will use the specific syntax of Ruby.

Acording to wikipedia Ruby is a dynamic, reflective, object-oriented, general-purpose programming language. It was designed and developed in the mid-1990s by Yukihiro "Matz" Matsumoto in Japan.

According to its authors, Ruby was influenced by Perl, Smalltalk, Eiffel, Ada, and Lisp. It supports multiple programming paradigms, including functional, object-oriented, and imperative. It also has a dynamic type system and automatic memory management.

Expressions

A expression is a combination or a set of values, functions, declarations, commands that adhere to the syntax and can be evaluated by the interpreter to produce a result.

When a program is being evaluated the first step the interpreter will do is check all the linked files and make sure there are no syntax errors.

There are different types of expressions:

  • explicit values
  • constant
  • variables
  • operators
  • functions

The code is then translated into a compiled version that can communicate with the lower level of the computer, to be actually be able to execute it.

The expressions are evaluated and loaded into memory into its own scope, variables and values are assigned, functions are created.

Scope is the context on which a expression is evaluated, it determines which values, variables and elements are available to use.

Programming languages attempt to disambiguate meanings, they're also less verbose, that's why expressions are used instead of using a language like English. If I was to say two plus two minus eleven it would be harder to read and interpret as opposed to 2 + 2 - 1, 2 + (2 - 1) or (2 + 2) - 1, that have different meanings.

Data Types

Data types or types are the type of information that a value has, it usually determines what kind of actions can you perform with a certain value.

Everything in Ruby is an object, meaning every value has properties and methods.

The following types are available in Ruby:

  • Constant
  • Hashes (Dictionaries)
  • Arrays
  • String
  • Numbers (Integers and Floats)

Running Ruby on the command line

We will use the interactive ruby console and create ruby files and execute them in the command line.

We will create a calculator program that takes a symbol and two numbers and applies the operation to them.

so ./calc.rb + 2 2 will output 4.

What is Rails? What is a framework

A framework, on the other hand, is a collection of code that uses an inversion-of-control mechanism to help you structure your code. Frameworks are similar to libraries in that they provide building blocks you can use to build a bigger system. They often come with a pre-imposed structure and philosophy of how to approach a domain of problems.

Rails comes with a group of libraries to connect to databases, respond to web requests, organize code, structurize an app. It uses the MVC pattern, it includes lots of tools and code generation that make common taks faster. It doesn't connect to the internet directly, by default is uses a web server called WEBrick but it can be plugged to any other web server like Apache or nginx.

It uses the convention over configuration method, meaning that any expected behavior should not require any code. Enforcing this conventions makes it easy for any developer with experience in Rails to take over or understand any other project written in Rails by anyone else in the world.

A cool way to learn more about Rails is Rails for Zombies.

Rails was created by David Heinemeier Hansson around 2005, is on its 4th version, it comes preinstalled in MacBooks since 2007.

About

Basic introduction to Ruby, learning data types, expressions, functions, variables and the basics of the ruby syntax.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published