Class: Array

Inherits:
Object
  • Object
show all
Defined in:
lib/ionize/translate/ext.rb

Instance Method Summary collapse

Instance Method Details

#composite_node?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/ionize/translate/ext.rb', line 23

def composite_node?
  self.first.is_a? Array
end

#replace_pattern(pattern, value) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
# File 'lib/ionize/translate/ext.rb', line 11

def replace_pattern(pattern, value)
  copy = self.dup
  (0..copy.length).each do |i|
    if copy[i] == pattern
      copy[i] = value
    elsif copy[i].is_a? Array
      copy[i] = copy[i].replace_pattern(pattern, value)
    end 
  end   
  copy
end

#restObject



7
8
9
# File 'lib/ionize/translate/ext.rb', line 7

def rest
  self[1..-1]
end

#to_blockObject



27
28
29
30
31
32
33
# File 'lib/ionize/translate/ext.rb', line 27

def to_block
  if self.composite_node?
    [:block] + self
  else
    self
  end
end