Module: Enumerable

Defined in:
lib/to-javascript/encoders/enumerable.rb

Instance Method Summary collapse

Instance Method Details

#to_js(options = {}) ⇒ Object

Returns a Javascript string representing the enumerable. Any options given will be passed on to its elements. For example:

users = User.find(:all)
# => users.to_js(:only => :name)

will pass the :only => :name option to each user.



9
10
11
# File 'lib/to-javascript/encoders/enumerable.rb', line 9

def to_js(options = {}) #:nodoc:
  ActiveSupport::JS::Code.new "[#{map { |value| ActiveSupport::JS.encode(value, options) } * ', '}]"
end