Class: Ferro::Sequence

Inherits:
Object
  • Object
show all
Defined in:
opal/opal-ferro/ferro_sequence.js.rb

Overview

A helper class to generate unique labels. These labels can be used to ensure unique instance variable names.

Instance Method Summary collapse

Constructor Details

#initialize(prefix = nil) ⇒ Sequence

Create a new sequence.

Parameters:

  • prefix (String) (defaults to: nil)

    a prefix for generated labels



10
11
12
13
# File 'opal/opal-ferro/ferro_sequence.js.rb', line 10

def initialize(prefix = nil)
  @prefix  = prefix
  @next_id = 0
end

Instance Method Details

#nextString

Get the next label.

Returns:

  • (String)

    the unique label



18
19
20
21
# File 'opal/opal-ferro/ferro_sequence.js.rb', line 18

def next
  @next_id += 1
  "#{@prefix}#{@next_id}"
end