- Github followup: forking
- Ruby overview
- Ruby expressions
- Ruby data types
- Ruby exercise: build a calculator
- Rails overview
- Homework review (from last class)
- Assignments
A fork is a copy of a repository. Forking a repository allows you to freely experiment with changes without affecting the original project.
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.
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.
- Dynamic
- Reflective
- Object-oriented
- General-purpose
- Functional programming
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 x 4 or (2 + 2) x 4, which have different meanings
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
- Symbols
- Numbers (Integers and Floats)
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.
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.