Ruby on Rails: a brief introduction -...

17
Ruby AN OVERVIEW Luigi De Russis Dipartimento di Automatica e Informatica Politecnico di Torino [email protected]

Transcript of Ruby on Rails: a brief introduction -...

Page 1: Ruby on Rails: a brief introduction - polito.itelite.polito.it/files/courses/02NPYPD/2013-2014/lucidi/moduloA/02-ru… · Installation (Ruby + Rails) We use Ruby 1.9.3 and Rails 3.2.x

Ruby AN OVERVIEW

Luigi De Russis

Dipartimento di Automatica e Informatica

Politecnico di Torino

[email protected]

Page 2: Ruby on Rails: a brief introduction - polito.itelite.polito.it/files/courses/02NPYPD/2013-2014/lucidi/moduloA/02-ru… · Installation (Ruby + Rails) We use Ruby 1.9.3 and Rails 3.2.x

What is Ruby?

Ruby is a dynamic, open source

programming language with a focus on

simplicity and productivity

It is an ideal language for scripting and

rapid application development in

many areas on most platforms

Linguaggi e Ambienti Multimediali A 2

Page 3: Ruby on Rails: a brief introduction - polito.itelite.polito.it/files/courses/02NPYPD/2013-2014/lucidi/moduloA/02-ru… · Installation (Ruby + Rails) We use Ruby 1.9.3 and Rails 3.2.x

Identikit

First appeared in 1995

Designed by Yukihiro “Matz” Matsumoto

General purpose

Object oriented

High level

Emphasis on human, rather than computer, needs

Website

◦ http://www.ruby-lang.org

Linguaggi e Ambienti Multimediali A 3

Page 4: Ruby on Rails: a brief introduction - polito.itelite.polito.it/files/courses/02NPYPD/2013-2014/lucidi/moduloA/02-ru… · Installation (Ruby + Rails) We use Ruby 1.9.3 and Rails 3.2.x

High level languages

Near to human-level abstraction

◦ short, expressive, easy to read

Portable

◦ can be executed on different platform with

few or none changes

Must be translated into low-level code for

actual execution

Linguaggi e Ambienti Multimediali A 4

Page 5: Ruby on Rails: a brief introduction - polito.itelite.polito.it/files/courses/02NPYPD/2013-2014/lucidi/moduloA/02-ru… · Installation (Ruby + Rails) We use Ruby 1.9.3 and Rails 3.2.x

Low level languages

Directly executable

◦ no translation needed

Typically more efficient

◦ they are designed for very specific hardware

Platform dependent

◦ must be re-written for execution on different

platforms

Difficult to write and read

◦ near to machine code

Linguaggi e Ambienti Multimediali A 5

Page 6: Ruby on Rails: a brief introduction - polito.itelite.polito.it/files/courses/02NPYPD/2013-2014/lucidi/moduloA/02-ru… · Installation (Ruby + Rails) We use Ruby 1.9.3 and Rails 3.2.x

Interpreted languages

Line by line translation and execution

Linguaggi e Ambienti Multimediali A 6

Source

code

Code

Interpreter Result

Page 7: Ruby on Rails: a brief introduction - polito.itelite.polito.it/files/courses/02NPYPD/2013-2014/lucidi/moduloA/02-ru… · Installation (Ruby + Rails) We use Ruby 1.9.3 and Rails 3.2.x

Compiled languages

Completely translated into low-level code

before execution

Linguaggi e Ambienti Multimediali A 7

Source

code

Code

Interpreter

Object

code

Executor Result

Page 8: Ruby on Rails: a brief introduction - polito.itelite.polito.it/files/courses/02NPYPD/2013-2014/lucidi/moduloA/02-ru… · Installation (Ruby + Rails) We use Ruby 1.9.3 and Rails 3.2.x

Ruby is interpreted

Two ways to use the interpreter

Interactive mode

◦ type the program and the interpreter displays

the result

Script mode

◦ store the code in a file, and use the

interpreter to execute the contents

Linguaggi e Ambienti Multimediali A 8

irb(main):001:0> 1+1

=> 2

ruby myscript.rb

Page 9: Ruby on Rails: a brief introduction - polito.itelite.polito.it/files/courses/02NPYPD/2013-2014/lucidi/moduloA/02-ru… · Installation (Ruby + Rails) We use Ruby 1.9.3 and Rails 3.2.x

RUBY (AND RAILS) INSTALL

Getting started

Linguaggi e Ambienti Multimediali A 9

Page 10: Ruby on Rails: a brief introduction - polito.itelite.polito.it/files/courses/02NPYPD/2013-2014/lucidi/moduloA/02-ru… · Installation (Ruby + Rails) We use Ruby 1.9.3 and Rails 3.2.x

Ruby availability

High level

◦ available for all platforms

Linux / Mac OS X

◦ typically pre-installed (maybe not in the

“right” version)

◦ already used for some tasks

Windows

◦ should be explicitly installed

Linguaggi e Ambienti Multimediali A 10

Page 11: Ruby on Rails: a brief introduction - polito.itelite.polito.it/files/courses/02NPYPD/2013-2014/lucidi/moduloA/02-ru… · Installation (Ruby + Rails) We use Ruby 1.9.3 and Rails 3.2.x

Installation (Ruby + Rails)

We use Ruby 1.9.3

◦ and Rails 3.2.x

In Room 5T

◦ everything is set up under Windows

At home

◦ feel free to use the operating system you

prefer

◦ we will try to give support for Linux, Mac OS

X and Windows

Linguaggi e Ambienti Multimediali A 11

Page 12: Ruby on Rails: a brief introduction - polito.itelite.polito.it/files/courses/02NPYPD/2013-2014/lucidi/moduloA/02-ru… · Installation (Ruby + Rails) We use Ruby 1.9.3 and Rails 3.2.x

Windows Installation

Download RailsInstaller

◦ http://railsinstaller.org/

◦ version 2.2.2

◦ follow the wizard

throughout installation

Check that everything goes ok

◦ open a command prompt

Win(+R) > cmd

ruby -v

Linguaggi e Ambienti Multimediali A 12

Page 13: Ruby on Rails: a brief introduction - polito.itelite.polito.it/files/courses/02NPYPD/2013-2014/lucidi/moduloA/02-ru… · Installation (Ruby + Rails) We use Ruby 1.9.3 and Rails 3.2.x

Linux / Mac OS X

On the course website (Link section)

◦ instructions in PDF

◦ scripts tested in Ubuntu and Mavericks

We recommend to use:

◦ rbenv for installing Ruby

https://github.com/sstephenson/rbenv

◦ plus homebrew (Mac only)

http://brew.sh/

Linguaggi e Ambienti Multimediali A 13

Page 14: Ruby on Rails: a brief introduction - polito.itelite.polito.it/files/courses/02NPYPD/2013-2014/lucidi/moduloA/02-ru… · Installation (Ruby + Rails) We use Ruby 1.9.3 and Rails 3.2.x

Integrated Development

Environment (IDE)

A software application that provides

comprehensive facilities to computer

programmers for software development.

An IDE normally consists of source code

editor, build automation tools and a

debugger.

Most modern IDEs offer Intelligent code

completion features.

Linguaggi e Ambienti Multimediali A 14

Page 15: Ruby on Rails: a brief introduction - polito.itelite.polito.it/files/courses/02NPYPD/2013-2014/lucidi/moduloA/02-ru… · Installation (Ruby + Rails) We use Ruby 1.9.3 and Rails 3.2.x

Ruby/Rails IDE

Some choices available

We use JetBrains RubyMine

◦ http://jetbrains.com/ruby

RubyMine is a commercial product

JetBrains gives us an educational

license for this course

◦ available on the teaching portal

◦ it will expire on January 20, 2015

Linguaggi e Ambienti Multimediali A 15

Page 16: Ruby on Rails: a brief introduction - polito.itelite.polito.it/files/courses/02NPYPD/2013-2014/lucidi/moduloA/02-ru… · Installation (Ruby + Rails) We use Ruby 1.9.3 and Rails 3.2.x

Hello world!

Linguaggi e Ambienti Multimediali A 16

Page 17: Ruby on Rails: a brief introduction - polito.itelite.polito.it/files/courses/02NPYPD/2013-2014/lucidi/moduloA/02-ru… · Installation (Ruby + Rails) We use Ruby 1.9.3 and Rails 3.2.x

This work is licensed under the Creative Commons “Attribution-NonCommercial-ShareAlike Unported (CC BY-NC-SA 3,0)” License.

You are free:

◦ to Share - to copy, distribute and transmit the work

◦ to Remix - to adapt the work

Under the following conditions:

◦ Attribution - You must attribute the work in the manner specified by the author or licensor (but not in any way that suggests that they endorse you or your use of the work).

◦ Noncommercial - You may not use this work for commercial purposes.

◦ Share Alike - If you alter, transform, or build upon this work, you may distribute the resulting work only under the same or similar license to this one.

To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/3.0/

17

License