Class: ActionView::RenderParser::RipperASTParser::Node
- Inherits:
 - 
      Array
      
        
- Object
 - Array
 - ActionView::RenderParser::RipperASTParser::Node
 
 
- Defined in:
 - lib/action_view/ripper_ast_parser.rb
 
Overview
:nodoc:
Instance Attribute Summary collapse
- 
  
    
      #type  ⇒ Object 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    
Returns the value of attribute type.
 
Instance Method Summary collapse
- #argument_nodes ⇒ Object
 - #call? ⇒ Boolean
 - #call_method_name ⇒ Object
 - #children ⇒ Object
 - #fcall? ⇒ Boolean
 - #fcall_named?(name) ⇒ Boolean
 - #hash? ⇒ Boolean
 - #hash_from_body(body) ⇒ Object
 - 
  
    
      #initialize(type, arr, opts = {})  ⇒ Node 
    
    
  
  
  
    constructor
  
  
  
  
  
  
  
    
A new instance of Node.
 - #inspect ⇒ Object
 - #string? ⇒ Boolean
 - #symbol? ⇒ Boolean
 - #to_hash ⇒ Object
 - #to_string ⇒ Object
 - #to_symbol ⇒ Object
 - #variable_name ⇒ Object
 - #variable_reference? ⇒ Boolean
 - #vcall? ⇒ Boolean
 
Constructor Details
#initialize(type, arr, opts = {}) ⇒ Node
Returns a new instance of Node.
      11 12 13 14  | 
    
      # File 'lib/action_view/ripper_ast_parser.rb', line 11 def initialize(type, arr, opts = {}) @type = type super(arr) end  | 
  
Instance Attribute Details
#type ⇒ Object (readonly)
Returns the value of attribute type.
      9 10 11  | 
    
      # File 'lib/action_view/ripper_ast_parser.rb', line 9 def type @type end  | 
  
Instance Method Details
#argument_nodes ⇒ Object
      35 36 37 38 39 40 41 42 43  | 
    
      # File 'lib/action_view/ripper_ast_parser.rb', line 35 def argument_nodes raise unless fcall? return [] if self[1].nil? if self[1].last == false || self[1].last.type == :vcall self[1][0...-1] else self[1][0..-1] end end  | 
  
#call? ⇒ Boolean
      57 58 59  | 
    
      # File 'lib/action_view/ripper_ast_parser.rb', line 57 def call? type == :call end  | 
  
#call_method_name ⇒ Object
      65 66 67  | 
    
      # File 'lib/action_view/ripper_ast_parser.rb', line 65 def call_method_name self.last.first end  | 
  
#children ⇒ Object
      16 17 18  | 
    
      # File 'lib/action_view/ripper_ast_parser.rb', line 16 def children to_a end  | 
  
#fcall? ⇒ Boolean
      25 26 27  | 
    
      # File 'lib/action_view/ripper_ast_parser.rb', line 25 def fcall? type == :command || type == :fcall end  | 
  
#fcall_named?(name) ⇒ Boolean
      29 30 31 32 33  | 
    
      # File 'lib/action_view/ripper_ast_parser.rb', line 29 def fcall_named?(name) fcall? && self[0].type == :@ident && self[0][0] == name end  | 
  
#hash? ⇒ Boolean
      74 75 76  | 
    
      # File 'lib/action_view/ripper_ast_parser.rb', line 74 def hash? type == :bare_assoc_hash || type == :hash end  | 
  
#hash_from_body(body) ⇒ Object
      88 89 90 91 92 93 94  | 
    
      # File 'lib/action_view/ripper_ast_parser.rb', line 88 def hash_from_body(body) body.map do |hash_node| return nil if hash_node.type != :assoc_new [hash_node[0], hash_node[1]] end.to_h end  | 
  
#inspect ⇒ Object
      20 21 22 23  | 
    
      # File 'lib/action_view/ripper_ast_parser.rb', line 20 def inspect typeinfo = type && type != :list ? ":" + type.to_s + ", " : "" "s(" + typeinfo + map(&:inspect).join(", ") + ")" end  | 
  
#string? ⇒ Boolean
      45 46 47  | 
    
      # File 'lib/action_view/ripper_ast_parser.rb', line 45 def string? type == :string_literal end  | 
  
#symbol? ⇒ Boolean
      96 97 98  | 
    
      # File 'lib/action_view/ripper_ast_parser.rb', line 96 def symbol? type == :@label || type == :symbol_literal end  | 
  
#to_hash ⇒ Object
      78 79 80 81 82 83 84 85 86  | 
    
      # File 'lib/action_view/ripper_ast_parser.rb', line 78 def to_hash if type == :bare_assoc_hash hash_from_body(self[0]) elsif type == :hash && self[0] == nil {} elsif type == :hash && self[0].type == :assoclist_from_args hash_from_body(self[0][0]) end end  | 
  
#to_string ⇒ Object
      69 70 71 72  | 
    
      # File 'lib/action_view/ripper_ast_parser.rb', line 69 def to_string raise unless string? self[0][0][0] end  | 
  
#to_symbol ⇒ Object
      100 101 102 103 104 105 106 107 108  | 
    
      # File 'lib/action_view/ripper_ast_parser.rb', line 100 def to_symbol if type == :@label && self[0] =~ /\A(.+):\z/ $1.to_sym elsif type == :symbol_literal && self[0].type == :symbol && self[0][0].type == :@ident self[0][0][0].to_sym else raise "not a symbol?: #{self.inspect}" end end  | 
  
#variable_name ⇒ Object
      61 62 63  | 
    
      # File 'lib/action_view/ripper_ast_parser.rb', line 61 def variable_name self[0][0] end  | 
  
#variable_reference? ⇒ Boolean
      49 50 51  | 
    
      # File 'lib/action_view/ripper_ast_parser.rb', line 49 def variable_reference? type == :var_ref end  | 
  
#vcall? ⇒ Boolean
      53 54 55  | 
    
      # File 'lib/action_view/ripper_ast_parser.rb', line 53 def vcall? type == :vcall end  |