Class: DYI::Script::EcmaScript::Function
- Inherits:
-
SimpleScript
- Object
- SimpleScript
- DYI::Script::EcmaScript::Function
- Defined in:
- lib/dyi/script/ecmascript.rb
Overview
Class representing a function of ECMAScript. The scripting becomes effective only when it is output by SVG format.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#arguments ⇒ Array<String>
readonly
Returns an array of formal parameter identifiers on ECMAScript.
-
#name ⇒ String?
readonly
Returns a function identifier on ECMAScript.
Attributes inherited from SimpleScript
Instance Method Summary collapse
-
#contents ⇒ String
Returns string expression of this function in ECMAScript.
-
#initialize(body, name = nil, *arguments) ⇒ Function
constructor
A new instance of Function.
Methods inherited from SimpleScript
#append_body, #has_uri_reference?, #include_external_file?, #write_as
Constructor Details
#initialize(body, name = nil, *arguments) ⇒ Function
Returns a new instance of Function.
346 347 348 349 350 351 352 353 354 355 356 357 358 |
# File 'lib/dyi/script/ecmascript.rb', line 346 def initialize(body, name=nil, *arguments) super(body) if name && name !~ /\A[\$A-Z_a-z][\$0-9A-Z_a-z]*\z/ raise ArgumentError, "illegal identifier: `#{name}'" end @name = name @arguments = arguments.map do |arg| if arg.to_s !~ /\A[\$A-Z_a-z][\$0-9A-Z_a-z]*\z/ raise ArgumentError, "illegal identifier: `#{arg}'" end arg.to_s end end |
Instance Attribute Details
#arguments ⇒ Array<String> (readonly)
Returns an array of formal parameter identifiers on ECMAScript.
340 341 342 |
# File 'lib/dyi/script/ecmascript.rb', line 340 def arguments @arguments end |
#name ⇒ String? (readonly)
Returns a function identifier on ECMAScript.
337 338 339 |
# File 'lib/dyi/script/ecmascript.rb', line 337 def name @name end |
Instance Method Details
#contents ⇒ String
Returns string expression of this function in ECMAScript
363 364 365 366 367 368 369 370 371 372 373 |
# File 'lib/dyi/script/ecmascript.rb', line 363 def contents parts = [] parts << 'function' parts << " #{name}" if name parts << '(' parts << arguments.join(', ') parts << "){\n" parts << @body parts << "\n}" parts.join end |