Language > Static Methods and Attributes

# Static Methods and Attributes

This document describes how to use static methods and attributes. Also see:

- Creating Static Methods
- List of Static Methods and Attributes

### Using Variable Attributes

All IDL variables can use the dot "." operator to access various attributes that describe the variable.

All variables have special attributes that return information about the variable. These attributes are equivalent to calling the N_ELEMENTS, SIZE, or TYPENAME functions.

For example:

IDL> arr = FLTARR(200, 100)

IDL> arr.LENGTH, arr.NDIM, arr.DIM, arr.TNAME

IDL prints:

20000

2

200 100

FLOAT

See Variable Attributes for the list of available attributes.

### Using Static Methods

All IDL variables (except structures and objects) have access to static methods. These are implemented as methods on "static classes," where the variable's data type determines the class. For example, an IDL variable of type BYTE has a built-in static class named IDL_Byte. The static classes have the following inheritance structure:

Note that all of IDL's integer types are a subclass of IDL_Integer, which is a subclass of IDL_Number, which in turn is a subclass of IDL_Variable. This means that all integer variables will have access to any of the methods on IDL_Integer, IDL_Number, and IDL_Variable. Similarly, all floating-point variables will have access to the methods on IDL_Number and IDL_Variable.

When a static method is called, the IDL variable is passed into the method as the first argument. The "self" argument (normally used for object class methods) is undefined. The static method can return a variable of any IDL type as the result of the function call.

For example, we will use the IDL_Integer::BitShift method to divide a byte array by 2, use the IDL_Variable::Uniq method to find the unique elements, and then convert the array to a string:

IDL> arr = BYTE([146,146,146,136,136,152,152,152,66,66,66,66])

IDL> arr = arr.BitShift(-1)

IDL> HELP, arr

IDL> newarr = arr.Uniq(/NO_SORT)

IDL> HELP, newarr

IDL> print, newarr.ToASCII()

IDL prints:

ARR BYTE = Array[12]

NEWARR BYTE = Array[4]

IDL!

For the list of available static methods, see Static Methods and Attributes.