Created
June 11, 2018 13:03
-
-
Save elyosemite/b98500546cf21fc03f233b28f92a9e45 to your computer and use it in GitHub Desktop.
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 Produto | |
| def initialize(attrs) | |
| # Se o meu hash estiver com dados então atribua | |
| if attrs.present? | |
| self.id = attrs["id"] | |
| self.nome = attrs["nome"] | |
| end | |
| end | |
| attr_accessor :id, :nome | |
| def self.buscar | |
| produtos = ActiveRecord::Base.connection.exec_query("SELECT * FROM produtos") | |
| return produtos.map{ |p| Produto.new(p) } | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment