123456789_123456789_123456789_123456789_123456789_

Class: ActionView::RenderParser::RipperRenderParser::Node

Do not use. This class is for internal use only.
Relationships & Source Files
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
self, ::Array
Instance Chain:
self, ::Array
Inherits: Array
  • ::Object
Defined in: actionview/lib/action_view/render_parser/ripper_render_parser.rb

Class Method Summary

::Array - Inherited

.wrap

Wraps its argument in an array unless it is already an array (or array-like).

Instance Attribute Summary

Instance Method Summary

::Array - Inherited

#blank?

An array is blank if it’s empty:

#deep_dup

Returns a deep copy of array.

#excluding

Returns a copy of the ::Array excluding the specified elements.

#extract!

Removes and returns the elements for which the block returns a true value.

#extract_options!

Extracts options from a set of arguments.

#fifth

Equal to self[4].

#forty_two

Equal to self[41].

#fourth

Equal to self[3].

#from

Returns the tail of the array from position.

#in_groups

Splits or iterates over the array in number of groups, padding any remaining slots with fill_with unless it is false.

#in_groups_of

Splits or iterates over the array in groups of size number, padding any remaining slots with fill_with unless it is false.

#including

Returns a new array that includes the passed elements.

#inquiry

Wraps the array in an ::ActiveSupport::ArrayInquirer object, which gives a friendlier way to check its string-like contents.

#second

Equal to self[1].

#second_to_last

Equal to self[-2].

#split

Divides the array into one or more subarrays based on a delimiting value or the result of an optional block.

#third

Equal to self[2].

#third_to_last

Equal to self[-3].

#to

Returns the beginning of the array up to position.

#to_formatted_s

Alias for Array#to_fs.

#to_fs

Extends Array#to_s to convert a collection of elements into a comma separated id list if :db argument is given as the format.

#to_param

Calls to_param on all its elements and joins the result with slashes.

#to_query

Converts an array into a string suitable for use as a URL query string, using the given key as the param name.

#to_sentence

Converts the array to a comma-separated sentence where the last element is joined by the connector word.

#to_xml

Returns a string that represents the array in XML by invoking to_xml on each element.

#without

Alias for Array#excluding.

#as_json,
#compact_blank!

Removes all blank elements from the ::Array in place and returns self.

Constructor Details

.new(type, arr, opts = {}) ⇒ Node

[ GitHub ]

  
# File 'actionview/lib/action_view/render_parser/ripper_render_parser.rb', line 9

def initialize(type, arr, opts = {})
  @type = type
  super(arr)
end

Instance Attribute Details

#call?Boolean (readonly)

[ GitHub ]

  
# File 'actionview/lib/action_view/render_parser/ripper_render_parser.rb', line 55

def call?
  type == :call
end

#fcall?Boolean (readonly)

[ GitHub ]

  
# File 'actionview/lib/action_view/render_parser/ripper_render_parser.rb', line 23

def fcall?
  type == :command || type == :fcall
end

#hash?Boolean (readonly)

[ GitHub ]

  
# File 'actionview/lib/action_view/render_parser/ripper_render_parser.rb', line 81

def hash?
  type == :bare_assoc_hash || type == :hash
end

#string?Boolean (readonly)

[ GitHub ]

  
# File 'actionview/lib/action_view/render_parser/ripper_render_parser.rb', line 43

def string?
  type == :string_literal
end

#symbol?Boolean (readonly)

[ GitHub ]

  
# File 'actionview/lib/action_view/render_parser/ripper_render_parser.rb', line 103

def symbol?
  type == :@label || type == :symbol_literal
end

#type (readonly)

[ GitHub ]

  
# File 'actionview/lib/action_view/render_parser/ripper_render_parser.rb', line 7

attr_reader :type

#variable_reference?Boolean (readonly)

[ GitHub ]

  
# File 'actionview/lib/action_view/render_parser/ripper_render_parser.rb', line 47

def variable_reference?
  type == :var_ref
end

#vcall?Boolean (readonly)

[ GitHub ]

  
# File 'actionview/lib/action_view/render_parser/ripper_render_parser.rb', line 51

def vcall?
  type == :vcall
end

Instance Method Details

#argument_nodes

[ GitHub ]

  
# File 'actionview/lib/action_view/render_parser/ripper_render_parser.rb', line 33

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_method_name

[ GitHub ]

  
# File 'actionview/lib/action_view/render_parser/ripper_render_parser.rb', line 63

def call_method_name
  self[2].first
end

#children

[ GitHub ]

  
# File 'actionview/lib/action_view/render_parser/ripper_render_parser.rb', line 14

def children
  to_a
end

#fcall_named?(name) ⇒ Boolean

[ GitHub ]

  
# File 'actionview/lib/action_view/render_parser/ripper_render_parser.rb', line 27

def fcall_named?(name)
  fcall? &&
    self[0].type == :@ident &&
    self[0][0] == name
end

#hash_from_body(body)

[ GitHub ]

  
# File 'actionview/lib/action_view/render_parser/ripper_render_parser.rb', line 95

def hash_from_body(body)
  body.to_h do |hash_node|
    return nil if hash_node.type != :assoc_new

    [hash_node[0], hash_node[1]]
  end
end

#inspect

[ GitHub ]

  
# File 'actionview/lib/action_view/render_parser/ripper_render_parser.rb', line 18

def inspect
  typeinfo = type && type != :list ? ":" + type.to_s + ", " : ""
  "s(" + typeinfo + map(&:inspect).join(", ") + ")"
end

#to_hash

[ GitHub ]

  
# File 'actionview/lib/action_view/render_parser/ripper_render_parser.rb', line 85

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

[ GitHub ]

  
# File 'actionview/lib/action_view/render_parser/ripper_render_parser.rb', line 67

def to_string
  raise unless string?

  # s(:string_literal, s(:string_content, map))
  self[0].map do |node|
    case node.type
    when :@tstring_content
      node[0]
    when :string_embexpr
      "*"
    end
  end.join("")
end

#to_symbol

[ GitHub ]

  
# File 'actionview/lib/action_view/render_parser/ripper_render_parser.rb', line 107

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

[ GitHub ]

  
# File 'actionview/lib/action_view/render_parser/ripper_render_parser.rb', line 59

def variable_name
  self[0][0]
end