Inheritance is defined using the is argument to contract:

contract :Child, is: [:ERC721, :Ownable]

This causes all of ERC721's and Ownable's functions, events, and state variables to be merged into Child.

Virtual and Override Modifiers

When a contract inherits from another, Rubidity automatically merges functions from parent contracts. If both parent and child contracts have a function with the same name, the child's function will override the parent's function, provided that the parent function is marked as virtual and the child's function is marked as override.

For example, a typical ERC721 parent contract transferFrom would be marked virtual:

function :transferFrom, { from: :address, to: :address, id: :uint256 }, :public, :virtual do
  # Parent Logic

Which would allow a child to override it like this:

function :transferFrom, { from: :address, to: :address, id: :uint256 }, :public, :override do
  # Child-specific logic
  ERC721.transferFrom(from: from, to: to, id: id)

Calling Parent Functions

In Rubidity there is no super. Instead, parent functions are called as methods on the parent contract constant, as above:

ERC721.transferFrom(from: from, to: to, id: id)

Parent constructors work in the same way as normal parent functions, for example:

ERC721.constructor(name: name, symbol: symbol)

Last updated