Rubidity by Example
Let's start with some examples from Solidity's introduction.
Storage Example
This basic Solidity contract sets the value of a variable and then exposes it to others to access:
Here is how this logic translates to Rubidity:
Looking point by point, here's what the Solidity version does and how Rubidity translates it.
Contract Definition
Solidity:
contract SimpleStorage { ... }
Rubidity:
contract :SimpleStorage
In Solidity, you define a contract using the
contract
keyword. In Rubidity, you define a contract using thecontract
method.
State Variables
Solidity:
uint storedData;
Rubidity:
uint256 :storedData
Solidity uses the
uint
keyword to define a state variable. Rubidity uses a Ruby symbol to define a state variable along with its type, in this case,uint256
.
Function Definitions
Set Function
Solidity:
Rubidity:
Aside from the use of symbols and the fact that function definition keywords are separated with commas, the implementations are quite similar. The biggest difference is that in Rubidity all function arguments must be named and also that all state variables are prefixed with s.
Get Function
Solidity:
Rubidity:
Get as well is practically identical.
Constructor
Unlike Solidity, an explicit constructor is required in Rubidity.
Accessing State
In Rubidity, state variables are accessed using the s.
prefix, as seen in s.storedData = x
and return s.storedData
. Writing to state using an unprefixed variable is not possible in Rubidity.
Last updated