cevado
Should `__info__(:attributes)` accumulate multiple instances of the same attribute?
so I was using MyModule.__info__(:attributes)[:behaviour] to make sure a module implements a behaviour but when the module has 2 or more behaviour definition it has several :behaviour keys, each one with a list of just one behaviour module.
is this the intended behaviour or should we have just one key :behaviour with a list of all behaviours?
Marked As Solved
josevalim
That’s how Erlang stores multiple attributes, which we reproduce for compatibility.
Also Liked
LostKobrakai
There’s already a setting for module attributes, which controls if their values are accumulated or replaced.
dimitarvp
Even more concretely: Module.register_attribute
defmodule Xyz do
Module.register_attribute(__MODULE__, :cars, accumulate: true)
@cars "Toyota"
def do_stuff(), do: IO.puts("hey there")
@cars ", "
@cars "Hyundai"
def show_cars(), do: IO.puts(@cars)
end
Then in iex:
iex(1)> Xyz.show_cars()
Hyundai, Toyota
:ok
Note that if you put integers they’ll be accumulated in a list. Strings however just get appended at the end of the previous value.
cevado
It was for this PR
I assumed it would accumulate, and did a wrong implementation in the first PR:







