https://github.com/andrewvy/method_missing
Elixir Library for dynamic code execution
https://github.com/andrewvy/method_missing
elixir enterprise-ready professional-people
Last synced: over 1 year ago
JSON representation
Elixir Library for dynamic code execution
- Host: GitHub
- URL: https://github.com/andrewvy/method_missing
- Owner: andrewvy
- Created: 2017-03-02T16:11:45.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2017-03-02T17:12:00.000Z (over 9 years ago)
- Last Synced: 2024-04-14T05:57:10.057Z (about 2 years ago)
- Topics: elixir, enterprise-ready, professional-people
- Language: Elixir
- Size: 3.91 KB
- Stars: 6
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# 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
```elixir
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](https://hex.pm/docs/publish), 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
```
2. Ensure `method_missing` is started before your application:
```elixir
def application do
[applications: [:method_missing]]
end
```