Class: Toybox::Lang::Symbol

Inherits:
Object
  • Object
show all

Overview

A Symbol is a lightweight constant identifier.

The Monkey C compiler will assign a new value when it encounters a new Symbol. This allows a developer to use Symbol objects as keys or constant values without explicitly declaring a constant or enum. While Symbol values are constant for a build, their values may change across builds. For this reason, Symbol objects should not be used for persistent data.

Examples:

var person = {:first_name=>"Bob", :last_name=>"Jones"};

Since:

  • 1.0.0

Instance Method Summary collapse

Methods inherited from Object

equals, hashCode, method, weak

Instance Method Details

toNumberNumber

Convert a Symbol to a Number

This will return a number containing the integer value of the symbol.

Returns:

  • (Number)

    The number representation of the Symbol

Since:

  • 2.3.0


6915
6916
# File 'Monkeybrains.rb', line 6915

def toNumber()
end

toStringString

Convert a Symbol to a String

This will return the string for the name of the symbol in development builds. Because Monkey C does not contain runtime reflection information in release builds, the returned string will be different and will follow the format “symbol (num)”. In this format, “num” is the integer value of the symbol.

Returns:

  • (String)

    The String representation of the Symbol

Since:

  • 1.0.0


6907
6908
# File 'Monkeybrains.rb', line 6907

def toString()
end