Skip to content

Instantly share code, notes, and snippets.

@douglasmartins7
Created May 11, 2018 17:38
Show Gist options
  • Save douglasmartins7/b726567f76ac7a7ce3ca41534c623e03 to your computer and use it in GitHub Desktop.
Save douglasmartins7/b726567f76ac7a7ce3ca41534c623e03 to your computer and use it in GitHub Desktop.
Ruby
# inserir modulos dentro da estancia
module Validacoes
def validar_cpf
true
end
def validar_cnpj
false
end
end
a = "Douglas"
a.extended Validacoes
###############################################
module Teste
def oi
"ola"
end
end
String.include Teste # eu incluo o modulo Teste direto no objeto String
# entao se for chamado qualquer objeto do tipo String ele entedera o metodo oi
"sei la".oi #funciona
"Dahh".oi #funciona
String.extended Teste
include eu insiro na estancia
extended eu insiro na classe
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment