Class: Nodo::Script
- Inherits:
-
Object
- Object
- Nodo::Script
- Defined in:
- lib/nodo/script.rb
Instance Attribute Summary collapse
-
#code ⇒ Object
readonly
Returns the value of attribute code.
Instance Method Summary collapse
-
#initialize(code = nil, &block) ⇒ Script
constructor
A new instance of Script.
- #to_js ⇒ Object
Constructor Details
#initialize(code = nil, &block) ⇒ Script
Returns a new instance of Script.
5 6 7 8 |
# File 'lib/nodo/script.rb', line 5 def initialize(code = nil, &block) raise ArgumentError, 'cannot give code when block is given' if code && block @code = code || block end |
Instance Attribute Details
#code ⇒ Object (readonly)
Returns the value of attribute code.
3 4 5 |
# File 'lib/nodo/script.rb', line 3 def code @code end |
Instance Method Details
#to_js ⇒ Object
10 11 12 13 |
# File 'lib/nodo/script.rb', line 10 def to_js js = code.respond_to?(:call) ? code.call : code "#{js}\n" end |