Class: LetItGo::WTFParser::BinaryCall

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

Overview

These are calls to operators that take 1 argument such as ‘1 + 1` or `[] << 1`

Instance Method Summary collapse

Constructor Details

#initialize(ripped_code) ⇒ BinaryCall

[

[:string_literal, [:string_content, [:@tstring_content, "hello", [1, 7]]]],
:+,
[:string_literal,
 [:string_content, [:@tstring_content, "there", [1, 17]]]]]


151
152
153
154
155
# File 'lib/let_it_go/wtf_parser.rb', line 151

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

Instance Method Details

#arg_typesObject



166
167
168
# File 'lib/let_it_go/wtf_parser.rb', line 166

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

#argsObject



162
163
164
# File 'lib/let_it_go/wtf_parser.rb', line 162

def args
  [@raw.last]
end

#method_nameObject

For ‘1 + 1` we want to pull “+”



158
159
160
# File 'lib/let_it_go/wtf_parser.rb', line 158

def method_name
  @raw[1].to_s
end