In Elixir, is there any way to get a module to list its functions?

前端 未结 3 1867
情话喂你
情话喂你 2020-12-25 09:25

In the same way that we can get any object (or class) in Ruby to list its methods, is there any function in Elixir to list all functions belonging to a module? Something (a

3条回答
  •  北海茫月
    2020-12-25 09:54

    Each module in Elixir defines an __info__ function you can call to get information about that module.

    According the Elixir Docs, 1.6.6 e.g., you can pass it :functions to get a list of functions that module contains.

    Map.__info__(:functions)
    
    [delete: 2, drop: 2, equal?: 2, fetch: 2, fetch!: 2, from_struct: 1, get: 2,
     get: 3, has_key?: 2, keys: 1, merge: 2, merge: 3, new: 0, pop: 2, pop: 3,
     put: 3, put_new: 3, size: 1, split: 2, take: 2, to_list: 1, update: 4,
     update!: 3, values: 1]
    

提交回复
热议问题