Skip to content

Instantly share code, notes, and snippets.

@bcardarella
Last active August 2, 2025 00:07
Show Gist options
  • Save bcardarella/7ed0a084ead39e8ded92bd07a89b453b to your computer and use it in GitHub Desktop.
Save bcardarella/7ed0a084ead39e8ded92bd07a89b453b to your computer and use it in GitHub Desktop.
defmodule LivingThing do
use GenObject, [
..living traits...
]
...living functions...
end
defmodule Mammal do
use LivingThing, [
...
]
defmacro __using__(fields) do
quote do
use Furred
require Inherit
Inherit.setup(unquote(__MODULE__), unquote(fields))
end
end
end
defmodule Dog do
use Mammal, [
name: "",
breed: "",
colors: [],
hypoallegenic?: true
]
defmacro __using__(fields) do
use Trainable
use Breedable
require Inherit
Inherit.setup(unquote(__MODULE__), unquote(fields))
end
end
defmodule GoldenDoodle do
use Dog, [
breed: :golen_doodle
hypoallegenic?: true,
colors: [:yellow]
]
end
defmodule Lab do
use Dog, [
breed: :lab
]
end
defmodule ChocolateLab do
use Lab, [
colors: [:chocolate]
]
end
ChocolateLab.new(name: "Wiley")
GoldenDoodle.new(name: "Boomer")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment