Class: Red::DefinitionNode::Class
- Inherits:
-
Red::DefinitionNode
- Object
- String
- Red::DefinitionNode
- Red::DefinitionNode::Class
- Defined in:
- lib/red/nodes/definition_nodes.rb
Overview
:nodoc:
Instance Method Summary collapse
-
#initialize(class_name_sexp, superclass_sexp, scope_sexp, options = {}) ⇒ Class
constructor
- :class, :Foo, (expression), [:scope, (expression | :block)]
-
> superclass doesn’t show up sometimes when namespaced a certain way; I forgot what the pattern is though.
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(class_name_sexp, superclass_sexp, scope_sexp, options = {}) ⇒ Class
- :class, :Foo, (expression), [:scope, (expression | :block)]
-
> superclass doesn’t show up sometimes when namespaced a certain way; I forgot what the pattern is though
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/red/nodes/definition_nodes.rb', line 14 def initialize(class_name_sexp, superclass_sexp, scope_sexp, = {}) ( = scope_sexp) && (scope_sexp = superclass_sexp) && (superclass_sexp = nil) if scope_sexp.is_a?(Hash) superclass = (superclass_sexp || [:const, :Object]).red! class_name = "%s" % class_name_sexp.red! if class_name_sexp.is_sexp?(:colon3) old_namespace_stack = @@namespace_stack namespaced_class = class_name @@namespace_stack = [namespaced_class] elsif class_name_sexp.is_sexp?(:colon2) @@namespace_stack.push(class_name) namespaced_class = class_name class_name = class_name_sexp.last.red! else class_name = "c$%s" % class_name_sexp.red! @@namespace_stack.push(class_name) namespaced_class = @@namespace_stack.join(".") end @@red_constants |= [namespaced_class] scope = scope_sexp.red!(:as_class_eval => true) self << "\n\nRed._class('%s',%s,function(){ var _=%s.prototype;\n %s;\n})" % [namespaced_class.gsub("c$",""), superclass, namespaced_class, scope] old_namespace_stack.nil? ? @@namespace_stack.pop : @@namespace_stack = old_namespace_stack end |