cevado

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

josevalim

Creator of Elixir

That’s how Erlang stores multiple attributes, which we reproduce for compatibility.

Also Liked

LostKobrakai

LostKobrakai

There’s already a setting for module attributes, which controls if their values are accumulated or replaced.

dimitarvp

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

cevado

It was for this PR

I assumed it would accumulate, and did a wrong implementation in the first PR:

Where Next?

Popular in Questions Top

quazar
How to set Jason to encode all fields in ecto schema, I don’t care about security and implementing only is taking long list of attributes...
New
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New
hariharasudhan94
I would like to know what is the best IDE for elixir development?
New
Phillipp
Hey, I have a NanoPi-M3 and try to install Elixir on their Ubuntu image. I followed the Raspberry Pi installation instructions from the ...
New
gonzofish
I’m currently trying to understand how to join three tables using Ecto. All the examples I’ve seen use 2, so maybe I’m just missing somet...
New
baxterw3b
Hi guys, i’m new in the Elixir world, and i have to say, that i love it! i’m having some problem to understand anonymous functions with ...
New
Fl4m3Ph03n1x
About me? ( if you have nothing better to do than reading about some random guy in the internet :stuck_out_tongue: ) Hello all, this is ...
New
sabri
Can someone explain the settings of pool_size of Ecto in config file? and what is the recommend size? Thanks
New
Codball
Mix format works fine if run from the cmd. I’ve followed this to facilitate the implementation into VSC which involves downloading an ext...
New
jay1
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New

Other popular topics Top

yurko
Here are few pieces of (common) Linux knowledge that we use for reasonably small one server apps. We use Ubuntu but this should work for ...
New
JakeBecker
TL;DR: I’ve just released an implementation of Microsoft’s IDE-independent Language Server Protocol for Elixir. It adds language support ...
1140 51847 244
New
srinivasu
How to handle excepions in elixir? Suppose i have A, B, C ,D, E modules. and each module has get() function. A.get() method will call th...
New
axelson
This post is a wiki (feel free to hit the edit button near the bottom right of this post to add your own changes!) This post collects co...
239 45766 226
New
quazar
How to set Jason to encode all fields in ecto schema, I don’t care about security and implementing only is taking long list of attributes...
New
chrismccord
This release brings a number of exciting features, including integration with the new Phoenix LiveDashboard and Phoenix LiveView. There h...
New
hariharasudhan94
I would like to know what is the best IDE for elixir development?
New
vertexbuffer
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
chrisalley
ExUnit now has describe blocks which is a welcome addition coming from RSpec. In the docs, it states that nested hierarchies of describe ...
New
Nvim
Elixir appears to be a superior language to Python. I don’t see any advantage of Python over Elixir. Are there any?
New

We're in Beta

About us Mission Statement