Exception: Alda::OrderError

Inherits:
StandardError
  • Object
show all
Defined in:
lib/alda-rb/error.rb

Overview

This error is raised when one tries to append events in an Alda::EventList in a wrong order.

Alda::Score.new do
  motif = f4 f e e d d c2
  g4 f e d c2 # It commented out, error will not occur
  c4 c g g a a g2 motif # (OrderError)
end

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(expected, got) ⇒ OrderError

:call-seq:

new(expected, got) -> Alda::OrderError

Creates a Alda::OrderError object.



159
160
161
162
163
# File 'lib/alda-rb/error.rb', line 159

def initialize expected, got
	super 'events are out of order'
	@expected = expected
	@got = got
end

Instance Attribute Details

#expectedObject (readonly)

The expected element gotten if it is of the correct order. See #got.

Alda::Score.new do
  motif = f4 f e e d d c2
  g4 f e d c2
  p @events.size # => 2
  c4 c g g a a g2 motif
rescue OrderError => e
  p @events.size # => 1
  p e.expected   # => #<Alda::EventContainer:...>
  p e.got        # => #<Alda::EventContainer:...>
end


147
148
149
# File 'lib/alda-rb/error.rb', line 147

def expected
  @expected
end

#gotObject (readonly)

The actually gotten element. For an example, see #expected.



152
153
154
# File 'lib/alda-rb/error.rb', line 152

def got
  @got
end