Skip to content

andrewvy/method_missing

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MethodMissing

Switched to Elixir and missed method_missing functionality in other languages?

This package is for you! It implements method_missing which you can bring into any other module!

Usage

defmodule Dog do
  use MethodMissing

  def method_missing(func, _args) do
    func_name = Atom.to_string(func)

    cond do
      Regex.match?(~r/bark|woof/, func_name) -> "WOOF"
      true -> "?"
    end
  end
end

Dog.bark()
> "WOOF"
Dog.woof()
> "WOOF"
Dog.meow()
> "?"

Why?

¯\_(ツ)_/¯

If you like weird great things, check out https://github.com/wojtekmach/oop

Installation

If available in Hex, the package can be installed as:

  1. Add method_missing to your list of dependencies in mix.exs:
```elixir
def deps do
  [{:method_missing, "~> 0.1.0"}]
end
```
  1. Ensure method_missing is started before your application:
```elixir
def application do
  [applications: [:method_missing]]
end
```

About

Elixir Library for dynamic code execution

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages