Class: Red::DefinitionNode::Scope
- Inherits:
-
Red::DefinitionNode
- Object
- String
- Red::DefinitionNode
- Red::DefinitionNode::Scope
- Defined in:
- lib/red/nodes/definition_nodes.rb
Overview
:nodoc:
Instance Method Summary collapse
-
#initialize(contents_sexp = nil, options = {}) ⇒ Scope
constructor
[:scope, (expression | :block)].
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(contents_sexp = nil, options = {}) ⇒ Scope
- :scope, (expression | :block)
157 158 159 160 161 162 163 164 165 166 167 |
# File 'lib/red/nodes/definition_nodes.rb', line 157 def initialize(contents_sexp = nil, = {}) ( = contents_sexp) && (contents_sexp = [:block]) if contents_sexp.is_a?(::Hash) variables = [] contents_sexp.flatten.each_with_index do |x,i| variables.push(contents_sexp.flatten[i + 1]) if x == :lasgn end variables -= (contents_sexp.delete(contents_sexp.assoc(:args)) || [])[1..-1] || [] # don't want to undefine the arguments in a method definition declare = "var %s" % variables.map {|x| "%s=$u" % x.red! }.uniq.join(",") unless variables.empty? contents = [declare, contents_sexp.red!()].compact.join(";#{[:as_class_eval] ? "\n " : ''}") self << "%s" % contents end |