Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Ruby on Rails it's ecosystem

Ruby on Rails it's ecosystem

Como surgiu o Ruby e o Rails.

Frankyston Lins Nogueira

March 30, 2019
Tweet

More Decks by Frankyston Lins Nogueira

Other Decks in Programming

Transcript

  1. @frankyston https://frankyston.dev class MyClass include Enumerable end class MyClass2 <

    MyClass def my_method end end class MyClass self.my_method puts "Método de classe" end end class MyClass2 < MyClass private def my_method end end
  2. @frankyston https://frankyston.dev if i > 10 puts "maior que 10"

    elseif i ==10 puts " igual a10" else puts "Menor que 10" end for a in (1..6) puts a end 6.times { |t| puts t }
  3. @frankyston https://frankyston.dev def chama_bloco yield('ola', 99) end chama_bloco {|str, num|

    puts str + ' ' + num.to_s} chama_bloco do |str, num| puts str + ' ' + num.to_s end
  4. @frankyston https://frankyston.dev array = [1, 2, 3, 5, 6, 7,

    8, 9, 10] array.each { |element| puts element } array.each_with_index do |index, element| puts "#{index} => #{element}” end
  5. @frankyston https://frankyston.dev ruby '2.2.5' source 'https://rubygems.org' gem 'rails' gem 'pg'

    gem 'bootstrap-sass' gem ‘simple_form' group :production do gem 'lograge', '0.10.0' gem 'newrelic_rpm', '3.15.0.314' gem 'therubyracer', '0.12.2' end group :development, :test do gem 'pry-meta', '0.0.10' gem 'resque-mock', '0.1.1' gem 'rspec-rails', '3.4.2' gem 'rubocop', '0.50.0', require: false end
  6. @frankyston https://frankyston.dev class User < ActiveRecord::Base def self.all_active where("state =

    ?", "active") end def self.all_inactive where("state = ?", "inactive") end def active? self.state == 'active' end def inactive? self.state == 'inactive' end end
  7. @frankyston https://frankyston.dev class User < ActiveRecord::Base
 
 STATES = ['active',

    'inactive']
 
 class <<self
 STATES.each do |state_name|
 define_method "all_#{state_name}" do
 where("state = ?", state_name)
 end
 end
 end
 
 STATES.each do |state_name|
 define_method "#{state_name}?" do
 self.state == state_name
 end
 end
 end
  8. @frankyston https://frankyston.dev class Person < ActiveRecord::Base end person = Person.new

    person.name = "Frankyston" person.age = 20 person.save person = Person.find(1) puts person.name # Frankyston person = Person.find_by_age(30) puts person.name # Frankyston
  9. @frankyston https://frankyston.dev require File.dirname(__FILE__) + '/../test_helper' class UserTest < Test::Unit::TestCase

    fixtures :users # Replace this with your real tests. def test_truth assert true end end
  10. @frankyston https://frankyston.dev class User < ActiveRecord::Base validates :firstname, presence: true

    validates :lastname, presence: true validates :email, presence: true, uniqueness: true end describe User do it "é válido quando nome, último nome e email estão presentes" do user = User.new( firstname: 'Bruce', lastname: 'Dickinson', email: '[email protected]' ) expect(user).to be_valid end end