Module: YardAstEditable

Defined in:
lib/yard_ast_editable.rb

Defined Under Namespace

Classes: Fcall

Constant Summary collapse

FCALL_TYPES =
[:fcall, :command].freeze

Instance Method Summary collapse

Instance Method Details

#fcall_by_ident(fcall_ident) ⇒ Object

メソッドを見つける fcall_ident: メソッド名



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/yard_ast_editable.rb', line 48

def fcall_by_ident(fcall_ident)
  fcall_ident = fcall_ident.to_s
  traverse do |child|
    if FCALL_TYPES.include?(child.type)
      if child[0].source == fcall_ident
        if block_given?
          return(child) if yield(Fcall.new(child))
        else
          return(child)
        end
      end
    end
  end
  nil
end

#replace_source(node, new_source) ⇒ Object



74
75
76
77
78
# File 'lib/yard_ast_editable.rb', line 74

def replace_source(node, new_source)
  result = full_source.dup
  result[node.source_range] = new_source
  result
end