Last active
October 9, 2018 00:50
-
-
Save aristotelesbr/daaae824ce5b7c2d7876ca312c59f089 to your computer and use it in GitHub Desktop.
module example
This file contains 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
# Module.rb | |
module Account | |
def default_attributes | |
super.merge(common_attributes) | |
end | |
def common_attributes | |
{ | |
name: '', | |
state: '', | |
city: '' | |
} | |
end | |
end | |
# Account.rb | |
class AccountUser | |
include Account | |
def default_attributes | |
{ | |
cpf: '' | |
} | |
end | |
end | |
# AccountStore | |
class AccountStore | |
include Account | |
def default_attributes | |
{ | |
cnpj: '' | |
} | |
end | |
end | |
# Note que AccountUser fica antes de Account | |
AccountUser.ancestors. | |
=> [AccountStore, Account, Object, Kernel, BasicObject] | |
AccountUser.new.default_attributes | |
=> {:cnpj=>""} | |
AccountUser.new.common_attributes | |
=> {:name=>"", :state=>"", :city=>""} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment