1 of 34

2 of 34

Sony Fermino dos Santos

  • Physicist
  • Programmer
  • Systems Analyst
  • Civil Servant
  • Writer

3 of 34

About Ruby

  • Japan, 1995, Yukihiro "Matz" Matsumoto
  • Functional, OO, imperative, reflective
  • Python, Perl, Smalltalk, Eiffel, Ada and Lisp

puts "Hello World!"

4 of 34

My Evolution

  • Until 2000: BASIC, Clipper, Z80 Assembly, Pascal, C, C++...
  • After 2000:
    • Delphi
    • PHP (and CSS, JS, MySQL)
    • Ruby

5 of 34

Delphi

Pros:

  • easy to design
  • practical for programming
  • ideal for Windows

Cons:

  • instalation on several machines
  • double work: screens and reports

6 of 34

PHP - Pros

  • easy to learn and to program
  • ready for web
  • flexible
  • free (as in speech and in beer)
  • you just pass the link to users
  • screens (pages) == reports

7 of 34

PHP - Cons

  • polluted namespace: array_*(...)
  • very complex when project’s size increases
  • so much typing
  • not a native OO language

8 of 34

Adding fruits to the basket - PHP

9 of 34

Adding fruits to the basket - Ruby

10 of 34

Adding fruits in chunks

11 of 34

Adding fruits in chunks

PHP:

Ruby:

12 of 34

Python vs Ruby: Personal Appeals

Python:

13 of 34

Python vs Ruby: Personal Appeals

Python: Ruby:

14 of 34

Speaking Dog

Python:

15 of 34

Speaking Dog

Python: Ruby:

16 of 34

Ruby Object Model

BasicObject

Object

Module

Class

Kernel

String

Fixnum

"love"

1337

is instance of Object

is subclass of Class

includes Module

17 of 34

Open Classes

18 of 34

Open Classes

19 of 34

Open Classes

20 of 34

Open Classes

Solution: Refinements!

(since Ruby 2.0)

21 of 34

Ruby Gems

Gem (precious stone, as ruby is):

  • groups features that can be reused in other projects;
  • allows easy sharing with other developers for free (rubygems.org).

gem install mysql2 sequel sinatra mail sqlite3

rubygems.org

Gems Public Library

22 of 34

DSL: Domain-Specific Language

You can create another language inside Ruby to work more directly in a specific domain

23 of 34

Sequel DSL for SQL

24 of 34

Sequel DSL for SQL

25 of 34

Sinatra DSL for web apps

26 of 34

Ruby Best Practices

  • Conventions
  • Benchmark
  • Unit Testing
    • Test::Unit, RSpec, Shoulda, Expectations…
  • Documentation
    • RDoc, ri, YARD...

27 of 34

Best Practices: Benchmark

28 of 34

Best Practices: Unit Testing

29 of 34

Best Practices: Documentation

30 of 34

Front-end in Ruby

31 of 34

Ruby drawbacks

  • Many ways to do the same thing
    • requires to analyse which way reaches the best result, which is more recommended, which is faster, which is more quick to program, which is more maintenable...
    • benchmark tests
    • research in blogs, forums, StackOverflow, etc.
  • Methods that return a valid object or nil
    • you can program your methods, but many built-in classes’ methods return a valid object or nil, so you have to check for nil frequently.
  • backtrace doesn’t show the parameters’ values
    • it would turn the debugging process much easier

32 of 34

Installing

  • Your linux native package manager
    • apt-get, rpm, yum…
  • Ruby Versions Manager
    • RVM, rbenv
  • Docker
    • docker pull ruby:2.3.1
    • see https://hub.docker.com/_/ruby/
  • RubyInstaller (Windows)

33 of 34

Documentation and Tutorials

34 of 34

The End