Programming Model

Ruff Programing Concepts

The following is the simplest example of a Ruff app:

$.ready(function() {


In ruff, a device object is an abstraction of a real-world hardware device.

Select device

We need to find a device in order to operate it. Ruff provides following API to select a device.


Using the format $(‘led-0’), we locate a device with the ID led-0.

Define the device

In order to make the selector work, we must first add the device and set up its ID. If you don’t know your device’s model name, please check our RAP repository.

Add a device using a rap command as follows:

rap device add your-device-id

Here we define your-device-id, which will be used within $(‘your-device-id’) selector in your code.

When you add a device, you must enter the correct model name and install the corresponding drivers and dependencies.

This command will also add a device’s information such as ID and model name into package.json and app.json.


Packages are like libraries or utilities. They allow Ruff developers to share and re-use their work so that others don’t waste time trying to re-invent wheels.

There are a few types of packages in Ruff:

  • Modules are regular JavaScript packages.
  • Drivers allow software to control hardware such as sensors, servos, etc.
  • Boards and drivers for boards (e.g., Ruff board).

Check our RAP repository for packages contributed by other developers.

Install packges

There are two basic approaches to installing packages.

1. Direct install

Using rap is always the easiest way to install.

rap install your-package-name --save

rap will find your-package-name in the RAP reopsitory. If the package exists it will be automatically downloaded and installed, and package.json will be updated.

2. Using package.json

If you want to install multiple packages, an alternative solution would be modify package.json, add all the dependencies, and then install using following command:

rap install

This will allow you to install multiple packages simultaneously.


Another type of dependencies, devDependencies, will not be deployed on the board. They will only be used to develop.

You may add a devDependency using the following command:

rap install your-rap-name --save-dev

Alternatively, you may declare devDependencies in package.json and execute installation as follows:

rap install


Currently a Ruff dev board can only run one application. Each app will have its own process. As an application developer, you can code in application functions that execute upon events. For example:

$.ready(function() {
// do initialization work


$.end(function() {
// do cleanup work


Default events

Ruff supports the following events by default:

  • ready allows you to specify a function to execute when the application process starts.
  • end allows you to specify a function to execute before the application process stops.