Skip to content

Contracts on self #191

Open
Open
@vlad-shatskyi

Description

@vlad-shatskyi

Let's say I have the following contracts

Contract Alkohol, Underaged => String
def sell(drink, person)
  "Sorry, come back in #{18 - person.age} years."
end

Contract Drink, Person => String
def sell(drink, person)
  "Here's your #{drink}."
end

full code

It works perfectly well, but let's say I want to define the sell method on Person. Now it becomes not obvious how would I check if the person is allowed to have the drink.

I propose to have some sort of self constraints. In Haskell-like syntax it would be

Contract :: (Underaged self) => Drink -> String

Metadata

Metadata

Assignees

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions