Class: Mack::JavaScript::Function

Inherits:
Object
  • Object
show all
Defined in:
lib/mack-javascript/helpers/script_generator.rb

Instance Method Summary collapse

Constructor Details

#initialize(session_id = nil, *args) ⇒ Function

Returns a new instance of Function.



174
175
176
177
178
179
180
181
# File 'lib/mack-javascript/helpers/script_generator.rb', line 174

def initialize(session_id = nil, *args)
  if args.first.is_a? Fixnum
    args = Array.new(args.first){|i| i + 1}.collect{|x| "obj#{x}"}
  end
  @session_id = session_id
  @arguments = args
  @generator = Mack::JavaScript::ScriptGenerator.new(session_id)
end

Instance Method Details

#<<(*args) ⇒ Object



183
184
185
186
# File 'lib/mack-javascript/helpers/script_generator.rb', line 183

def <<(*args)
  @generator << args
  to_s
end

#body {|@generator| ... } ⇒ Object

Yields:

  • (@generator)


188
189
190
191
# File 'lib/mack-javascript/helpers/script_generator.rb', line 188

def body(&block)
  yield @generator
  to_s
end

#to_sObject



193
194
195
# File 'lib/mack-javascript/helpers/script_generator.rb', line 193

def to_s
  "function(#{@arguments.join(', ')}){#{@generator.to_s}}"
end