Slide 1

Slide 1 text

Por que Ruby?

Slide 2

Slide 2 text

Por que Ruby? @samflores

Slide 3

Slide 3 text

No content

Slide 4

Slide 4 text

Genéticas

Slide 5

Slide 5 text

Genéticas Ambientais

Slide 6

Slide 6 text

Genéticas Ambientais Comportamentais

Slide 7

Slide 7 text

Objetividade

Slide 8

Slide 8 text

class DoNothing { public static void main(String[] args) { // não faz nada! } }

Slide 9

Slide 9 text

class DoNothing { public static void main(String[] args) { // não faz nada! } } # não faz nada!

Slide 10

Slide 10 text

class Person { private String name; private Date birthday; public String getName() { return name; } public void setName(String value) { name = value; } public String getBirthday() { return birthday; } public void setBirtday(String value) { birthday = value; } }

Slide 11

Slide 11 text

class Person { private String name; private Date birthday; public String getName() { return name; } public void setName(String value) { name = value; } public String getBirthday() { return birthday; } public void setBirtday(String value) { birthday = value; } } class Person attr_accessor :name, :birthday end

Slide 12

Slide 12 text

Expressividade

Slide 13

Slide 13 text

public void deliver() { if (message.length != 0) { connection.send(message) } }

Slide 14

Slide 14 text

public void deliver() { if (message.length != 0) { connection.send(message) } } def deliver connection.send(message) unless message.empty? end

Slide 15

Slide 15 text

// int[] list = [1, 2, 3, ..., 100]; for (int i = 0; i < list.length; i++) { printf("%d", list[i]); }

Slide 16

Slide 16 text

// int[] list = [1, 2, 3, ..., 100]; for (int i = 0; i < list.length; i++) { printf("%d", list[i]); } # list = (1..100).to_a list.each { |i| puts i }

Slide 17

Slide 17 text

state_machine :status, initial: :draft do event :deliver do transition draft: :sent end before_transition on: :deliver do throw :halt if receivers.empty? notify end end

Slide 18

Slide 18 text

Literais

Slide 19

Slide 19 text

Map map = new HashMap(); map.put("um", 1); map.put("dois", 2); map.put("três", 3);

Slide 20

Slide 20 text

Map map = new HashMap(); map.put("um", 1); map.put("dois", 2); map.put("três", 3); map = { "um" => 1, "dois" => 2, "três" => 3 }

Slide 21

Slide 21 text

String cpf = "123.456.789-00"; Pattern pattern = Pattern.compile("^\\d{3}\\.\\d{3}\\.\\d{3}-\\d{2}$"); Matcher matcher = pattern.matcher( cpf ); if (matcher.matches()) { System.out.println( "Formato de CPF válido" ); }

Slide 22

Slide 22 text

String cpf = "123.456.789-00"; Pattern pattern = Pattern.compile("^\\d{3}\\.\\d{3}\\.\\d{3}-\\d{2}$"); Matcher matcher = pattern.matcher( cpf ); if (matcher.matches()) { System.out.println( "Formato de CPF válido" ); } cpf = "123.456.789-00" if cpf =~ /^\d{3}\.\d{3}\.\d{3}-\d{2}$/ puts "Formato de CPF válido" end

Slide 23

Slide 23 text

Orientação a Objetos

Slide 24

Slide 24 text

"stressed".reverse # => desserts 1.odd? # => true receiver.non_existing_method # => pode ser que funcione ;) nil.nil? # => true

Slide 25

Slide 25 text

Programação Funcional

Slide 26

Slide 26 text

File.open("filename.txt") do |file| file.write("Some text") end (1..200).select do |number| number.prime? end code = -> { print "Hello world" } code.call

Slide 27

Slide 27 text

File.open("filename.txt") do |file| file.write("Some text") end (1..200).select do |number| number.prime? end code = -> { print "Hello world" } code.call do |file| file.write("Some text") end do |number| number.prime? end -> { print "Hello world" }

Slide 28

Slide 28 text

File.open("filename.txt") do |file| file.write("Some text") end (1..200).select do |number| number.prime? end code = -> { print "Hello world" } code.call number.prime?

Slide 29

Slide 29 text

Monkey Patch

Slide 30

Slide 30 text

class Fixnum def prime? return false if self < 2 return true if self == 2 factor = (2..(self / 2)).detect { |n| self % n == 0 } factor.nil? end end 31.prime? # => true

Slide 31

Slide 31 text

Metaprogramação

Slide 32

Slide 32 text

class Person < ActiveRecord::Base # no code here end person = Person.find_by_name_and_surname("Samuel", "Flores") person.name # => John person.birtday # => 1984-04-29

Slide 33

Slide 33 text

define_method method_missing* instance_eval class_eval

Slide 34

Slide 34 text

Packaging

Slide 35

Slide 35 text

> gem install nokogiri

Slide 36

Slide 36 text

> bundle install

Slide 37

Slide 37 text

junit junit 4.10 test com.h2database h2 ${h2database.version} test org.springframework spring-test ${org.springframework-version} test

Slide 38

Slide 38 text

junit junit 4.10 test com.h2database h2 ${h2database.version} test org.springframework spring-test ${org.springframework-version} test source "https://rubygems.org" gem 'sinatra', '1.4.1' gem 'dm-core', '1.2.0' gem 'dm-types', '1.2.2' gem 'dm-sqlite-adapter', '1.2.0' gem 'jdbc-sqlite3', '3.7.2', platforms: :jruby gem 'dm-zim-adapter', '0.0.1', platforms: :jruby gem 'do_zim', '0.0.1', platforms: :jruby gem 'dm-aggregates', '1.2.0' gem 'dm-validations', '1.2.0' gem 'dm-timestamps', '1.2.0' gem 'dm-serializer', '1.2.2' gem 'dm-migrations', '1.2.0'

Slide 39

Slide 39 text

Automação

Slide 40

Slide 40 text

> rake db:migrate

Slide 41

Slide 41 text

@{elseText}

Slide 42

Slide 42 text

@{elseText} desc 'Seed the DB' task :seed do Rake::Task['db:reset'].invoke seeds = TOML.load_file("db/seed.toml") time = Time.now seeds['user'].each do |key, attributes| User.create!(attributes.merge(created_at: time)) end end

Slide 43

Slide 43 text

Testes

Slide 44

Slide 44 text

class CalculatorTest < ActiveSupport::TestCase test "sum operation with more than 2 operands" do calc = Calculator.new assert calc.sum(1, 2, 3) == 6 end end

Slide 45

Slide 45 text

describe CalculatorTest do let(:calc) { Calculator.new } it "sums more than 2 operands" do calc.sum(1, 2, 3).should == 6 end end

Slide 46

Slide 46 text

Scenario: add more than two numbers Given I have entered 1 into the calculator And I have pressed the plus button And I have entered 2 into the calculator And I have pressed the plus button And I have entered 3 into the calculator When I press the equal button Then the result should be 6 on the screen

Slide 47

Slide 47 text

Web

Slide 48

Slide 48 text

> rails generate scaffold person name:string birthday:date active_record db/migrate/20130427142248_create_people.rb app/models/person.rb resource_route resources :people scaffold_controller app/controllers/people_controller.rb erb app/views/people app/views/people/index.html.erb app/views/people/edit.html.erb app/views/people/show.html.erb app/views/people/new.html.erb app/views/people/_form.html.erb . . .

Slide 49

Slide 49 text

post '/', provides: 'application/json' do order = Order.new(params[:order]) raise InvalidRecordError.new(order.errors) unless order.save order.to_json end

Slide 50

Slide 50 text

WEBrick Mongrel Thin Unicorn Rainbows Puma Passenger ...

Slide 51

Slide 51 text

Desktop

Slide 52

Slide 52 text

Shoes.app :height => 150, :width => 250 do background rgb(240, 250, 208) stack :margin => 10 do button "Start" do @time = Time.now @label.replace "Stop watch started at #@time" end button "Stop" do @label.replace "Stopped, ", strong("#{Time.now - @time}"), " seconds elapsed." end @label = para "Press ", strong("start"), " to begin timing." end end

Slide 53

Slide 53 text

Shoes.app :height => 150, :width => 250 do background rgb(240, 250, 208) stack :margin => 10 do button "Start" do @time = Time.now @label.replace "Stop watch started at #@time" end button "Stop" do @label.replace "Stopped, ", strong("#{Time.now - @time}"), " seconds elapsed." end @label = para "Press ", strong("start"), " to begin timing." end end

Slide 54

Slide 54 text

Open Source

Slide 55

Slide 55 text

Comunidade

Slide 56

Slide 56 text

TEST ALL THE TIME

Slide 57

Slide 57 text

Boas Práticas

Slide 58

Slide 58 text

Sociabilidade

Slide 59

Slide 59 text

Por que Ruby?

Slide 60

Slide 60 text

Por que não?

Slide 61

Slide 61 text

Produtividade & Diversão @yukihiro_matz

Slide 62

Slide 62 text

Tente Você vai gostar

Slide 63

Slide 63 text

Obrigado! @samflores