Class: Alda::SetVariable
- Includes:
- EventList
- Defined in:
- lib/alda-rb/event.rb
Overview
A set-variable event. Includes Alda::EventList.
An Alda::EventContainer containing an Alda::SetVariable can be derived using event list sugar. See Alda::EventList#method_missing.
There are several equivalent means of setting variable. Some of them can be ambiguous with Alda::InlineLisp or Alda::GetVariable, but it is intelligently chosen.
Alda::Score.new do
p var.event.class # => Alda::InlineLisp
p((var c d e f).event.class) # => Alda::SetVariable
p var { c d e f }.event.class # => Alda::SetVariable
p((var__ c d e f).event.class) # => Alda::SetVariable
p var__ { c d e f }.event.class # => Alda::SetVariable
p((var c d e f).event.class) # => Alda::Sequence
p var.event.class # => Alda::GetVariable
p var(1).event.class # => Alda::InlineLisp
end
Instance Attribute Summary collapse
-
#name ⇒ Object
The name of the variable.
Attributes included from EventList
Attributes inherited from Event
Instance Method Summary collapse
-
#==(other) ⇒ Object
:call-seq: set_variable == other -> true or false.
-
#initialize(name, *events, &block) ⇒ SetVariable
constructor
:call-seq: new(name, *events, &block) -> Alda::SetVariable.
-
#on_contained ⇒ Object
See Alda::Event#on_contained.
-
#to_alda_code ⇒ Object
:call-seq: to_alda_code() -> String.
Methods included from EventList
#events_alda_codes, #has_variable?, #import, #method_missing, #to_a
Methods inherited from Event
#detach_from_parent, #is_event_of?
Constructor Details
#initialize(name, *events, &block) ⇒ SetVariable
:call-seq:
new(name, *events, &block) -> Alda::SetVariable
Creates an Alda::SetVariable.
1205 1206 1207 1208 1209 |
# File 'lib/alda-rb/event.rb', line 1205 def initialize name, *events, &block @name = name.to_sym @events = events super &block end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Alda::EventList
Instance Attribute Details
#name ⇒ Object
The name of the variable.
1198 1199 1200 |
# File 'lib/alda-rb/event.rb', line 1198 def name @name end |
Instance Method Details
#==(other) ⇒ Object
:call-seq:
set_variable == other -> true or false
Overrides Alda::EventList#==. Returns true if the super method returns true and other
has the same #name as set_variable
(using ==
).
1237 1238 1239 |
# File 'lib/alda-rb/event.rb', line 1237 def == other super && @name == other.name end |
#on_contained ⇒ Object
See Alda::Event#on_contained.
1223 1224 1225 1226 1227 1228 |
# File 'lib/alda-rb/event.rb', line 1223 def on_contained super @parent.variables.add @name @events.detach_from_parent [self.class] @events.each { _1.parent = self if _1.is_a? Alda::Event } end |
#to_alda_code ⇒ Object
:call-seq:
to_alda_code() -> String
Specially, the returned value ends with a newline ā\nā. Overrides Alda::Event#to_alda_code.
1217 1218 1219 |
# File 'lib/alda-rb/event.rb', line 1217 def to_alda_code "#@name = #{events_alda_codes}\n" end |