Data Types

Rubidity is strongly-typed. This documentation aims to give you an overview of Rubidity's type system so you can create more robust and reliable applications.

Rubidity Types

Rubidity has most of Solidity's value types:

  • string

  • address

  • bytes32

  • bool

  • uint8–uint256

  • int8–int258

It also has these non-value types:

  • mapping (arbitrarily nested)

  • array (nesting not supported)

  • contract

Rubidity's Type System

When you declare a functions, event, or state variable you must specify the type, for example:

event :Transfer, { from: :address, to: :address, amount: :uint256 }

Then, when you pass values into the event the types must match:

emit :Transfer, from: msg.sender, to: to, amount: amount

Matching types can mean one of two things. Either the variable is actually typed, as in the case of msg.sender above, or the variable can be safely coerced into the type. For example the literal 5 can be coerced into a uint256, but isn't itself typed because it is a literal of the underlying Ruby language (which is not typed).

You should rarely have to do it, but if you want to declare a variable's type you can use the cast() method, for example val.cast(:uint256) or "hello".cast(:string)

Last updated