• Stars
    star
    294
  • Rank 141,303 (Top 3 %)
  • Language
    Elixir
  • Created almost 9 years ago
  • Updated over 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

OOP in Elixir!


oop

OOP

Build Status

Are you tired of all of that modules, processes and functions nonsense? Do you want to just use classes, objects and methods? If so, use OOP [1] library in Elixir [2]!

Demo

Lightning Talks - Wojtek Mach (ElixirConfEU 2016)

Example

import OOP

class Person do
  var :name

  def say_hello_to(who) do
    what = "Hello #{who.name}"
    IO.puts("#{this.name}: #{what}")
  end
end

joe = Person.new(name: "Joe")
mike = Person.new(name: "Mike")
robert = Person.new(name: "Robert")

joe.say_hello_to(mike)    # Joe: Hello Mike
mike.say_hello_to(joe)    # Mike: Hello Joe
mike.say_hello_to(robert) # Mike: Hello Robert
robert.say_hello_to(mike) # Robert: Hello Mike

joe.set_name("Hipster Joe")
joe.name # => Hipster Joe

An OOP library wouldn't be complete without inheritance:

class Animal do
  var :name
end

class Dog < Animal do
  var :breed
end

snuffles = Dog.new(name: "Snuffles", breed: "Shih Tzu")
snuffles.name # => "Snuffles"
snuffles.breed # => "Shih Tzu"

... or multiple inheritance:

class Human do
  var :name
end

class Horse do
  var :horseshoes_on?
end

class Centaur < [Human, Horse] do
end

john = Centaur.new(name: "John", horseshoes_on?: true)
john.name # => "John"
john.horseshoes_on? # => true

See more usage in the test suite.

Installation

Add oop to your list of dependencies in mix.exs:

def deps do
  [{:oop, "~> 0.1.0"}]
end

[1] According to Alan Kay, the inventor of OOP, "objects" is the lesser idea; the big idea is "messaging". In that sense, I can't agree more with Joe Armstrong's quote that Erlang is "possibly the only object-oriented language".

[2] Please don't. You've been warned.

License

The MIT License (MIT)

Copyright (c) 2015 Wojciech Mach

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

More Repositories

1

req

Req is a batteries-included HTTP client for Elixir.
Elixir
955
star
2

acme_bank

An example ☂ project
Elixir
748
star
3

mix_install_examples

A collection of simple Elixir scripts that are using Mix.install/2.
Elixir
535
star
4

mini_repo

MiniRepo allows self-hosting of Hex packages.
Elixir
191
star
5

elixir-run

Erlang/OTP + Elixir + IEx + Mix in a single executable for Linux/macOS/Windows. Just run Elixir!
Elixir
133
star
6

github_ecto

Ecto adapter for GitHub API
Elixir
120
star
7

calendar_interval

Functions for working with calendar intervals
Elixir
66
star
8

hello_beam

Elixir, Erlang, Gleam & LFE code all in the same project!
Erlang
64
star
9

phoenix_example

An example Phoenix app with one-click deployments to different cloud services.
Elixir
62
star
10

rubyfmt

Ruby
46
star
11

easyhtml

EasyHTML makes it easy to work with HTML in Elixir.
Elixir
43
star
12

minitest-capybara

**Deprecated** Capybara matchers support for minitest unit & spec
Ruby
41
star
13

minitest-metadata

Annotate tests with key/value metadata
Ruby
36
star
14

openapi

A proof-of-concept for generating OpenAPI clients in Elixir.
Elixir
28
star
15

calendar_recurrence

Recurrence is an Elixir library for working with recurring dates
Elixir
26
star
16

req_easyhtml

Req plugin for EasyHTML.
Elixir
22
star
17

shipit

ShipIt automates Hex package publishing to avoid common mistakes
Elixir
21
star
18

dotfiles

~wojtek
Shell
20
star
19

embedded_record

Embed objects in a bitmask field. Similar to bitmask-attribute and friends
Ruby
17
star
20

attrs

Yet another attributes on steroids gem
Ruby
17
star
21

ets_ecto

Elixir
16
star
22

phoenix_now

Elixir
14
star
23

easyxml

An experimental easy-to-use XML library for Elixir.
Elixir
13
star
24

req_s3

Elixir
10
star
25

system_castore

Elixir
9
star
26

php

Elixir
9
star
27

value_inspect

Provides implementation of #inspect that is arguably more readable and can be used in irb.
Ruby
9
star
28

que

Elixir
8
star
29

defc

Elixir
8
star
30

app_manifest

Elixir
8
star
31

mix_gen_callback

Mix task for generating a callback module for a given behaviour
Elixir
8
star
32

beamup-old

Shell
8
star
33

otp_builds_backup

Shell
7
star
34

req_hex

Elixir
7
star
35

system_target

Elixir
7
star
36

docs_chunks

Erlang
7
star
37

openurl

openurl
Elixir
7
star
38

jsonapi_ecto

Ecto adapter for any JSON API compatible backend
Elixir
6
star
39

rustler_playground

Rustler Playground makes it easy to create single-file Rustler applications.
Elixir
6
star
40

global_id

Elixir
6
star
41

beamup

Shell
6
star
42

vim-rename

Rename : Rename a buffer within Vim and on disk (by Christian J. Robinson)
Vim Script
6
star
43

backoff

Elixir
5
star
44

spec

Elixir
5
star
45

req_github_oauth

Elixir
5
star
46

unit

Elixir
5
star
47

bitfield

Elixir
5
star
48

fix

Elixir
5
star
49

poker_elixir

An Elixir library to work with Poker hands.
Elixir
5
star
50

nanorepo

Elixir
5
star
51

otp_docs

Shell
5
star
52

poker

Ruby poker library for evaluating hands
C
4
star
53

goth

Elixir
4
star
54

requests

Elixir
3
star
55

fluentx

Elixir
3
star
56

mix_deps_add

Elixir
3
star
57

code_info

Elixir
3
star
58

docker-beam

Dockerfile
3
star
59

kino_req

Elixir
3
star
60

rebar_ex2erl

Erlang
3
star
61

any_value

Collection of helper methods for testing "shape" of the data
Ruby
3
star
62

req_examples

Elixir
2
star
63

token_cache

Elixir
2
star
64

fs

Elixir
2
star
65

objc

Elixir
2
star
66

modulesdiff

Compare modules & functions between versions
Elixir
2
star
67

iex_help_open

Elixir
2
star
68

twirp_elixir

Elixir
2
star
69

hex_tar

Erlang
2
star
70

decimal_eval

Elixir
2
star
71

changelog

Print changelog of a Hex package
Elixir
2
star
72

sigil_z

Handles the ~Z sigil for UTC date times.
Elixir
2
star
73

mix_zig_cc

Elixir
2
star
74

signups

Experimental app showing how one test can be used on many levels: directly using app logic, against Web UI and API.
Ruby
2
star
75

minitest-capybara-example

Example Rails app for https://github.com/wojtekmach/minitest-capybara
Ruby
2
star
76

spdx

SPDX license list for Elixir
Elixir
2
star
77

macos_examples

Objective-C
1
star
78

automigrate

Elixir
1
star
79

inspect_record

Elixir
1
star
80

dotlocal

Serve your web app as myapp.local with minimal configuration
Elixir
1
star
81

playground

Elixir
1
star
82

twittr

Experiment
Elixir
1
star
83

exla

Elixir Client for XLA
C++
1
star
84

wx_demo

Elixir
1
star
85

goth_example

Elixir
1
star
86

chatty

Phoenix chat app. Based on: http://www.youtube.com/watch?v=RPs4SHpSThU
Elixir
1
star
87

catd

Polls for changes in some `foo.d/` directory and concatenates all files into one `foo`
Go
1
star
88

foo

Elixir
1
star
89

wx_examples

Elixir
1
star
90

mr-rebase

A bot that rebases PRs
Elixir
1
star
91

readmexec

Readmexec grabs commands from your README and runs them.
Ruby
1
star
92

open

Elixir
1
star
93

hippy

JavaScript
1
star
94

cmark_native

Elixir
1
star
95

phoenix_dashboard_clock

Elixir
1
star
96

rss

Elixir
1
star
97

bandit_mock

Elixir
1
star
98

slow_ex_unit

Elixir
1
star
99

elixirsh

Elixir
1
star
100

erl_doc_chunks

Erlang
1
star