Class: LetItGo::WTFParser::CommandCall

Inherits:
MethodAdd
  • Object
show all
Defined in:
lib/let_it_go/wtf_parser.rb

Overview

I think “command calls” are method invocations without parens Like ‘puts “hello world”`. For some unholy reason, their structure is different than regular method calls?

Instance Method Summary collapse

Methods inherited from MethodAdd

#args_paren, #call

Constructor Details

#initialize(ripped_code) ⇒ CommandCall

[

[:string_literal, [:string_content, [:@tstring_content, "foo", [1, 7]]]],
:".",
[:@ident, "gsub", [1, 12]],
[:args_add_block,
 [[:regexp_literal, [], [:@regexp_end, "/", [1, 18]]],
  [:call,
   [:string_literal,
    [:string_content, [:@tstring_content, "blerg", [1, 22]]]],
   :".",
   [:@ident, "downcase", [1, 29]]]],
 false]]


119
120
121
122
123
# File 'lib/let_it_go/wtf_parser.rb', line 119

def initialize(ripped_code)
  ripped_code = ripped_code.dup
  raise "Wrong node" unless ripped_code.shift == :command_call
  @raw = ripped_code
end

Instance Method Details

#arg_typesObject

Returns argument types as an array of symbols [:regexp_literal, :string_literal]



138
139
140
# File 'lib/let_it_go/wtf_parser.rb', line 138

def arg_types
  args.map(&:first).map {|x| x.is_a?(Array) ? x.first : x }.compact
end

#argsObject



133
134
135
# File 'lib/let_it_go/wtf_parser.rb', line 133

def args
  args_add_block.first(2).last || []
end

#args_add_blockObject



129
130
131
# File 'lib/let_it_go/wtf_parser.rb', line 129

def args_add_block
  @raw.find {|x| x.is_a?(Array) ? x.first == :args_add_block : false } || []
end

#method_nameObject



125
126
127
# File 'lib/let_it_go/wtf_parser.rb', line 125

def method_name
  @raw.find {|x| x.is_a?(Array) ? x.first == :@ident : false }[1]
end