# How to get count of current methods in a package's methodtable?

**URL:** <https://discourse.julialang.org/t/how-to-get-count-of-current-methods-in-a-packages-methodtable/7910>\
**Category:** General Usage\
**Tags:** question\
**Created:** [December 22, 2017, 5:21am UTC](https://discourse.julialang.org/t/how-to-get-count-of-current-methods-in-a-packages-methodtable/7910 "2017-12-22T05:21:43Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![djsegal](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/djsegal/32/13752_2.png) [@djsegal](https://discourse.julialang.org/u/djsegal)\
**Post date:** [December 22, 2017, 5:21am UTC](https://discourse.julialang.org/t/how-to-get-count-of-current-methods-in-a-packages-methodtable/7910/1 "2017-12-22T05:21:44Z")

</div>

The only tools I know to get information about methods are:

- `methods()`
- `methodswith()`
- (kind of) `fieldnames()`

How do you get information about the underlying method table though?

Is there a way to see how many methods there are in a table (at some point in time)?

---

<div class="post-metadata">

**Author:** ![djsegal](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/djsegal/32/13752_2.png) [@djsegal](https://discourse.julialang.org/u/djsegal)\
**Post date:** [December 22, 2017, 5:34am UTC](https://discourse.julialang.org/t/how-to-get-count-of-current-methods-in-a-packages-methodtable/7910/2 "2017-12-22T05:34:25Z")

</div>

Something that gets you close to this is:

```julia
function get_all_symbols(cur_package::Module)
  all_symbols = []

  for cur_name in cur_package.names(cur_package, true)
    Base.isidentifier(cur_name) || continue
    in(cur_name, (Symbol(cur_package), :eval)) && continue

    push!(all_symbols, cur_name)
  end

  all_symbols
end

```

---

<div class="post-metadata">

**Author:** ![ihnorton](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ihnorton/32/26_2.png) [@ihnorton](https://discourse.julialang.org/u/ihnorton)\
**Post date:** [December 22, 2017, 1:01pm UTC](https://discourse.julialang.org/t/how-to-get-count-of-current-methods-in-a-packages-methodtable/7910/3 "2017-12-22T13:01:45Z")

</div>

You can check whether a binding is callable with `isa(x, Base.Callable)`, which I believe implies it should have a method table entry.

---

<div class="post-metadata">

**Author:** ![djsegal](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/djsegal/32/13752_2.png) [@djsegal](https://discourse.julialang.org/u/djsegal)\
**Post date:** [December 22, 2017, 10:57pm UTC](https://discourse.julialang.org/t/how-to-get-count-of-current-methods-in-a-packages-methodtable/7910/4 "2017-12-22T22:57:21Z")

</div>

Would this be able to differentiate:

- `foo(bar::Baz`)
- `foo(bar::Fizz.Buzz)`

?

---

<div class="post-metadata">

**Author:** ![djsegal](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/djsegal/32/13752_2.png) [@djsegal](https://discourse.julialang.org/u/djsegal)\
**Post date:** [December 22, 2017, 10:59pm UTC](https://discourse.julialang.org/t/how-to-get-count-of-current-methods-in-a-packages-methodtable/7910/5 "2017-12-22T22:59:05Z")

</div>

Might have just answered that myself. Current func I’m working with:

```julia
function get_method_count(cur_package::Module)
  method_count = 0

  for cur_name in cur_package.names(cur_package, true)
    isdefined(cur_package, cur_name) || continue
    cur_obj = getfield(cur_package, cur_name)

    isa(cur_obj, Base.Callable) || continue
    method_count += length(methods(cur_obj))
  end

  method_count
end

```

---

<div class="post-metadata">

**Author:** ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)\
**Post date:** [December 23, 2017, 9:29am UTC](https://discourse.julialang.org/t/how-to-get-count-of-current-methods-in-a-packages-methodtable/7910/6 "2017-12-23T09:29:03Z")

</div>

A bit random question but do you intentionally put blank lines between all lines of code? It makes it difficult to read it.
