Skip to content

Instantly share code, notes, and snippets.

@aristotelesbr
Last active October 9, 2018 00:50
Show Gist options
  • Save aristotelesbr/daaae824ce5b7c2d7876ca312c59f089 to your computer and use it in GitHub Desktop.
Save aristotelesbr/daaae824ce5b7c2d7876ca312c59f089 to your computer and use it in GitHub Desktop.
module example
# 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