Class: Toybox::Lang::Method

Inherits:
Object
  • Object
show all

Overview

Method is a class that represents a callback, or a function that can be used as an argument to another function. You can create one using the method() call, and invoke the Method using the invoke() method.

Examples:

Using a callback function with a Timer

using Toybox.Timer;

var myCount = 0;

function timerCallback() {
    myCount += 1;
}

myTimer = new Timer.Timer();
myTimer.start(method(:timerCallback), 1000, true);

Invoking a Method

using Toybox.Lang;

function sensorIterator(type, options) {
    var sensors = [
        :getHeartRateHistory,
        :getTemperatureHistory,
        :getPressureHistory,
        :getElevationHistory
    ];

    var getSensorHistory = new Lang.Method(Toybox.SensorHistory, sensors[type]);
    return getSensorHistory.invoke(options);
}

enum {
    HEARTRATE,
    TEMPERATURE,
    PRESSURE,
    ELEVATION
}

var elevationIter = sensorIterator(ELEVATION, {:period => 10 });

See Also:

Since:

  • 1.0.0

Instance Method Summary collapse

Methods inherited from Object

equals, method, toString, weak

Constructor Details

initialize(aClass, aMethod) ⇒ Method

Method Constructor.

Parameters:

  • aClass

    Classdef of method (e.g. Toybox.SensorHistory)

  • aMethod (Toybox::Lang::Symbol)

    Symbol of class object

Since:

  • 1.0.0


7311
7312
# File 'Monkeybrains.rb', line 7311

def initialize(aClass, aMethod)
end

Instance Method Details

hashCodeToybox::Lang::Number

Get a hash code value for a Method. This computes a 32-bit Number that is typically used as an index when placing Objects into a Dictionary. Hash code values have the following characteristics:

  • The computed hash code is constant for the lifetime of an Object

  • If two Objects are equal, their hash codes will be equal

Returns:

See Also:

Since:

  • 1.0.0


7332
7333
# File 'Monkeybrains.rb', line 7332

def hashCode()
end

invoke(parameters) ⇒ Toybox::Lang::Object

Invoke a Method.

Parameters:

Returns:

Since:

  • 1.0.0


7319
7320
# File 'Monkeybrains.rb', line 7319

def invoke(parameters)
end