Class: LetItGo::WTFParser::MethodAdd
- Inherits:
-
Object
- Object
- LetItGo::WTFParser::MethodAdd
- Defined in:
- lib/let_it_go/wtf_parser.rb
Overview
Holds the “MethodAdd” components of parsed Ripper output Capable of pulling out ‘method_name`, and argument types such as :string_literal
Direct Known Subclasses
Instance Method Summary collapse
-
#arg_types ⇒ Object
Returns argument types as an array of symbols [:regexp_literal, :string_literal].
- #args ⇒ Object
-
#args_add_block ⇒ Object
[[:regexp_literal, [], [:@regexp_end, “/”, [1, 18]]], [[:call, [:string_literal, [:string_content, [:@tstring_content, “bar”, [1, 22]]]], :“.”, [:@ident, “gsub!”, [1, 27]]], [:arg_paren, [:args_add_block, [[:regexp_literal, [], [:@regexp_end, “/”, [1, 34]]], [:string_literal, [:string_content, [:@tstring_content, “zoo”, [1, 38]]]]], false]]]], false]]].
-
#args_paren ⇒ Object
[:arg_paren, [ :args_add_block, # .. ].
-
#call ⇒ Object
- :call, [:string_literal, [:string_content, [:@tstring_content, “foo”, [1, 7]]]], :“.”, [:@ident, “gsub”, [1, 12]
-
].
-
#initialize(ripped_code) ⇒ MethodAdd
constructor
A new instance of MethodAdd.
-
#method_name ⇒ Object
For gsub we want to pull from [:@ident, “gsub”, [1, 12]] from ‘call`.
Constructor Details
#initialize(ripped_code) ⇒ MethodAdd
Returns a new instance of MethodAdd.
24 25 26 27 28 |
# File 'lib/let_it_go/wtf_parser.rb', line 24 def initialize(ripped_code) ripped_code = ripped_code.dup raise "Wrong node" unless ripped_code.shift == :method_add_arg @raw = ripped_code end |
Instance Method Details
#arg_types ⇒ Object
Returns argument types as an array of symbols [:regexp_literal, :string_literal]
97 98 99 |
# File 'lib/let_it_go/wtf_parser.rb', line 97 def arg_types args.map(&:first).map {|x| x.is_a?(Array) ? x.first : x }.compact end |
#args ⇒ Object
79 80 81 82 83 84 85 86 87 88 |
# File 'lib/let_it_go/wtf_parser.rb', line 79 def args args = (args_add_block.first(2).last || []) case args.first when :args_add_star args.shift args else args end end |
#args_add_block ⇒ Object
[[:regexp_literal, [], [:@regexp_end, “/”, [1, 18]]],
[[:call,
[:string_literal,
[:string_content, [:@tstring_content, "bar", [1, 22]]]],
:".",
[:@ident, "gsub!", [1, 27]]],
[:arg_paren,
[:args_add_block,
[[:regexp_literal, [], [:@regexp_end, "/", [1, 34]]],
[:string_literal,
[:string_content, [:@tstring_content, "zoo", [1, 38]]]]],
false]]]],
false]]]
75 76 77 |
# File 'lib/let_it_go/wtf_parser.rb', line 75 def args_add_block args_paren.last || @raw.find {|x| x.first == :args_add_block } || [] end |
#args_paren ⇒ Object
[:arg_paren,
[
:args_add_block,
# ..
]
50 51 52 |
# File 'lib/let_it_go/wtf_parser.rb', line 50 def args_paren @raw.find {|x| x.first == :arg_paren } || [] end |
#call ⇒ Object
[
:call,
[:string_literal, [:string_content, [:@tstring_content, "foo", [1, 7]]]],
:".",
[:@ident, "gsub", [1, 12]]
]
36 37 38 |
# File 'lib/let_it_go/wtf_parser.rb', line 36 def call @raw.find {|x| x.first == :call || x.first == :fcall} end |
#method_name ⇒ Object
For gsub we want to pull from [:@ident, “gsub”, [1, 12]] from ‘call`
41 42 43 |
# File 'lib/let_it_go/wtf_parser.rb', line 41 def method_name call.find {|x| x.is_a?(Array) && x.first == :@ident }[1] end |