Class: Red::LiteralNode::Multiline
- Inherits:
-
Red::LiteralNode
- Object
- String
- Red::LiteralNode
- Red::LiteralNode::Multiline
- Defined in:
- lib/red/nodes/literal_nodes.rb
Overview
:nodoc:
Instance Method Summary collapse
-
#initialize(*expression_sexps) ⇒ Multiline
constructor
[:block, expression, expression, …].
Methods inherited from String
#%, #*, #+, #<<, #<=>, #==, #=~, #[], #[]=, #capitalize, #capitalize!, #casecmp, #center, #chomp, #chomp!, #chop, #chop!, #concat, #count, #crypt, #delete, #delete!, #downcase, #downcase!, #each, #each_byte, #each_line, #empty?, #eql?, #gsub, #gsub!, #hash, #hex, #include?, #index, #insert, #inspect, #intern, #length, #ljust, #lstrip, #lstrip!, #match, #next, #next!, #oct, #replace, #reverse, #reverse!, #rindex, #rjust, #rstrip, #rstrip!, #scan, #size, #slice, #slice!, #split, #squeeze, #strip, #strip!, #strip_scripts, #sub, #sub!, #succ, #succ!, #sum, #swapcase, #swapcase!, #to_f, #to_i, #to_s, #to_str, #to_sym, #tr, #tr!, #tr_s, #tr_s!, #upcase, #upcase!, #upto
Constructor Details
#initialize(*expression_sexps) ⇒ Multiline
- :block, expression, expression, …
25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/red/nodes/literal_nodes.rb', line 25 def initialize(*expression_sexps) # force_return: changes final expression to "return <expression>", # unless there is already return anywhere inside <expression>. # as_argument: duplicates :force_return and adds "function() { # <multiline block>; }()" wrapper to the entire block. = expression_sexps.pop if [:as_argument] || [:as_assignment] || .delete(:force_return) && expression_sexps.last.is_a?(::Array) && !expression_sexps.last.is_sexp?(:rescue, :ensure, :begin) && (expression_sexps.last.first == :iter ? true : !expression_sexps.last.flatten.include?(:return)) returner = "return %s" % [expression_sexps.pop.red!(:as_argument => true)] end string = [:as_argument] || [:as_assignment] ? "function(){%s;}.m$(this)()" : "%s" lines = (expression_sexps.map {|line| line.red!()} + [returner]).compact.reject {|x| x == '' }.join(";#{[:as_class_eval] ? "\n " : ''}") self << string % [lines] end |