Skip to content

Instantly share code, notes, and snippets.

@elyosemite
Created June 11, 2018 13:03
Show Gist options
  • Select an option

  • Save elyosemite/b98500546cf21fc03f233b28f92a9e45 to your computer and use it in GitHub Desktop.

Select an option

Save elyosemite/b98500546cf21fc03f233b28f92a9e45 to your computer and use it in GitHub Desktop.
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