Class: ActiveSupport::JS::Code

Inherits:
String show all
Defined in:
lib/to-javascript/code.rb

Overview

A string that returns itself as Javascript code.

Instance Method Summary collapse

Methods inherited from String

#as_js

Constructor Details

#initialize(object) ⇒ Code

Returns a new instance of Code.



19
20
21
22
23
24
25
26
27
# File 'lib/to-javascript/code.rb', line 19

def initialize(object)
  if object.is_a? String
    super(object)
  elsif object.respond_to? :to_js
    super(object.to_js)
  else
    super(object)
  end
end

Instance Method Details

#to_js(options = nil) ⇒ Object

Returns an unquoted string to be exectuted as Javacript code

{ :location => 'window.location'.as_js }.to_js
# => {"location": window.location}


33
34
35
# File 'lib/to-javascript/code.rb', line 33

def to_js(options=nil)
  self
end