This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Peca | |
| def self.iniciar | |
| @pecas = (0..6).collect {|lado1| | |
| (lado1..6).collect {|lado2| Peca.new(lado1, lado2) } | |
| }.flatten.shuffle | |
| end | |
| def self.proxima | |
| @pecas.pop | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Foo | |
| def initialize(&block) | |
| @block = block | |
| end | |
| def call | |
| @block.call | |
| end | |
| alias [] call | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def should_behave_like_resource(opts = {}) | |
| before :each do | |
| @opts = opts | |
| end | |
| def class_for(str) | |
| str.capitalize.constantize | |
| end | |
| def clazz |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # encoding: utf-8 | |
| module BrazilianDate | |
| def use_in_brazilian_format(*fields) | |
| unless methods.include?(:validate_dates) | |
| validate :validate_dates | |
| define_method :validate_dates do | |
| (@date_errors ||= {}).each_pair do |field, message| | |
| errors.add("#{field}_br".to_sym, message) | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| getattr(drew, "battle_cry")() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def total | |
| soma = 0 | |
| itens_orcamento.each {|item| soma += item.total } | |
| soma | |
| end | |
| def total | |
| itens_orcamento.map {|item| item.total }.sum | |
| end | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* Exemplos de testes (emulando o modo procedural) em Java */ | |
| /* Arquivo: FatorialTest.java */ | |
| package exercicio13; | |
| import static exercicio13.Fatorial.fatorial; | |
| import static org.junit.Assert.*; | |
| import org.junit.Test; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Arquivo fatorial_spec.rb | |
| require './fatorial' | |
| describe 'fatorial' do | |
| it 'calcula fatorial' do | |
| fatorial(0).should == 1 | |
| fatorial(1).should == 1 | |
| fatorial(2).should == 2 | |
| fatorial(3).should == 6 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Lista 1 de orientação a objetos | |
| ------------------------------- | |
| Utilizando TDD, elabore, em Java e em Ruby, os programas a seguir, utilizando | |
| orientação a objetos: | |
| 1) Crie uma classe que modele uma bola e permita trocar e consultar a cor da bola. A | |
| cor da bola é obrigatória. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class Numero { | |
| public long fatorial(long n) { | |
| if (n == 0) | |
| return 1; | |
| return n * fatorial(n - 1); | |
| } | |
| } |
OlderNewer