Class: StyleScript::SliceNode

Inherits:
Node
  • Object
show all
Defined in:
lib/style_script/nodes.rb

Overview

An array slice literal. Unlike JavaScript’s Array#slice, the second parameter specifies the index of the end of the slice (just like the first parameter) is the index of the beginning.

Constant Summary

Constants inherited from Node

Node::TAB

Instance Method Summary collapse

Methods inherited from Node

#children, children, #compile, #compile_closure, #contains?, #idt, statement, #statement?, statement_only, #statement_only?, top_sensitive, #top_sensitive?, #unwrap, #write

Constructor Details

#initialize(range) ⇒ SliceNode

Returns a new instance of SliceNode.



492
493
494
# File 'lib/style_script/nodes.rb', line 492

def initialize(range)
  @range = range
end

Instance Method Details

#compile_node(o) ⇒ Object



496
497
498
499
500
501
# File 'lib/style_script/nodes.rb', line 496

def compile_node(o)
  from      = @range.from.compile(o)
  to        = @range.to.compile(o)
  plus_part = @range.exclusive? ? '' : ' + 1'
  write(".slice(#{from}, #{to}#{plus_part})")
end