Class: RubyCop::NodeBuilder
- Inherits:
-
Ripper::SexpBuilder
- Object
- Ripper::SexpBuilder
- RubyCop::NodeBuilder
- Defined in:
- lib/ruby_cop/node_builder.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(src, filename = nil, lineno = nil) ⇒ NodeBuilder
constructor
A new instance of NodeBuilder.
- #on_alias(new_name, old_name) ⇒ Object
- #on_aref(target, args) ⇒ Object
- #on_aref_field(target, args) ⇒ Object
- #on_arg_paren(args) ⇒ Object
- #on_args_add(args, arg) ⇒ Object
- #on_args_add_block(args, block) ⇒ Object
- #on_args_new ⇒ Object
- #on_array(args) ⇒ Object
- #on_assign(lvalue, rvalue) ⇒ Object
- #on_assoc_new(key, value) ⇒ Object
- #on_assoclist_from_args(args) ⇒ Object
- #on_bare_assoc_hash(assocs) ⇒ Object
- #on_BEGIN(statements) ⇒ Object
- #on_begin(body) ⇒ Object
- #on_binary(lvalue, operator, rvalue) ⇒ Object
- #on_block_var(params, something) ⇒ Object
- #on_blockarg(arg) ⇒ Object
- #on_bodystmt(body, rescue_block, else_block, ensure_block) ⇒ Object
- #on_brace_block(params, statements) ⇒ Object
- #on_break(args) ⇒ Object
- #on_call(target, separator, identifier) ⇒ Object
- #on_case(args, when_block) ⇒ Object
- #on_CHAR(token) ⇒ Object
- #on_class(const, superclass, body) ⇒ Object
- #on_class_name_error(ident) ⇒ Object
- #on_command(identifier, args) ⇒ Object
- #on_command_call(target, separator, identifier, args) ⇒ Object
- #on_const(token) ⇒ Object
- #on_const_path_field(namespace, const) ⇒ Object
- #on_const_path_ref(namespace, const) ⇒ Object
- #on_const_ref(const) ⇒ Object
- #on_cvar(token) ⇒ Object
- #on_def(identifier, params, body) ⇒ Object
- #on_defined(ref) ⇒ Object
- #on_defs(target, separator, identifier, params, body) ⇒ Object
- #on_do_block(params, statements) ⇒ Object
- #on_dot2(min, max) ⇒ Object
- #on_dot3(min, max) ⇒ Object
- #on_dyna_symbol(symbol) ⇒ Object
- #on_else(statements) ⇒ Object
- #on_END(statements) ⇒ Object
- #on_ensure(statements) ⇒ Object
- #on_fcall(identifier) ⇒ Object
- #on_field(target, separator, identifier) ⇒ Object
- #on_float(token) ⇒ Object
- #on_for(variable, range, statements) ⇒ Object
- #on_gvar(token) ⇒ Object
- #on_hash(assocs) ⇒ Object
- #on_ident(token) ⇒ Object
- #on_if(expression, statements, else_block) ⇒ Object (also: #on_elsif)
- #on_if_mod(expression, statement) ⇒ Object
- #on_ifop(condition, then_part, else_part) ⇒ Object
- #on_int(token) ⇒ Object
- #on_ivar(token) ⇒ Object
- #on_kw(token) ⇒ Object
- #on_label(token) ⇒ Object
- #on_lambda(params, statements) ⇒ Object
- #on_massign(lvalue, rvalue) ⇒ Object
- #on_method_add_arg(call, args) ⇒ Object
- #on_method_add_block(call, block) ⇒ Object
- #on_mlhs_add(assignment, ref) ⇒ Object
- #on_mlhs_add_star(assignment, ref) ⇒ Object
- #on_mlhs_new ⇒ Object
- #on_module(const, body) ⇒ Object
- #on_mrhs_add(assignment, ref) ⇒ Object
- #on_mrhs_new_from_args(args) ⇒ Object
- #on_next(args) ⇒ Object
- #on_op(operator) ⇒ Object
- #on_opassign(lvalue, operator, rvalue) ⇒ Object
- #on_params(params, optionals, rest, something, block) ⇒ Object
- #on_paren(node) ⇒ Object
- #on_parse_error(message) ⇒ Object
- #on_program(statements) ⇒ Object
- #on_qwords_add(array, word) ⇒ Object
- #on_qwords_new ⇒ Object
- #on_redo ⇒ Object
- #on_regexp_add(regexp, content) ⇒ Object
- #on_regexp_literal(regexp, rdelim) ⇒ Object
- #on_regexp_new ⇒ Object
- #on_rescue(types, var, statements, block) ⇒ Object
- #on_rescue_mod(expression, statements) ⇒ Object
- #on_rest_param(param) ⇒ Object
- #on_retry ⇒ Object
- #on_return(args) ⇒ Object
- #on_sclass(superclass, body) ⇒ Object
- #on_stmts_add(target, statement) ⇒ Object
- #on_stmts_new ⇒ Object
- #on_string_add(string, content) ⇒ Object
- #on_string_concat(*strings) ⇒ Object
- #on_string_content ⇒ Object
-
#on_string_dvar(variable) ⇒ Object
weird string syntax that I didn’t know existed until writing this lib.
- #on_string_embexpr(expression) ⇒ Object
- #on_string_literal(string) ⇒ Object
- #on_super(args) ⇒ Object
- #on_symbol(token) ⇒ Object
- #on_symbol_literal(symbol) ⇒ Object
- #on_top_const_field(field) ⇒ Object
- #on_top_const_ref(const) ⇒ Object
- #on_tstring_content(token) ⇒ Object
- #on_unary(operator, operand) ⇒ Object
- #on_undef(args) ⇒ Object
- #on_unless(expression, statements, else_block) ⇒ Object
- #on_unless_mod(expression, statement) ⇒ Object
- #on_until(expression, statements) ⇒ Object
- #on_until_mod(expression, statement) ⇒ Object
- #on_var_alias(new_name, old_name) ⇒ Object
- #on_var_field(field) ⇒ Object
- #on_var_ref(ref) ⇒ Object (also: #on_vcall)
- #on_void_stmt ⇒ Object
- #on_when(expression, statements, next_block) ⇒ Object
- #on_while(expression, statements) ⇒ Object
- #on_while_mod(expression, statement) ⇒ Object
- #on_word_add(string, word) ⇒ Object
- #on_word_new ⇒ Object
- #on_words_add(array, word) ⇒ Object
- #on_words_new ⇒ Object
- #on_xstring_add(string, content) ⇒ Object
- #on_xstring_literal(string) ⇒ Object
- #on_xstring_new ⇒ Object
- #on_yield(args) ⇒ Object
- #on_yield0 ⇒ Object
- #on_zsuper ⇒ Object
Constructor Details
#initialize(src, filename = nil, lineno = nil) ⇒ NodeBuilder
Returns a new instance of NodeBuilder.
3 4 5 6 7 |
# File 'lib/ruby_cop/node_builder.rb', line 3 def initialize(src, filename=nil, lineno=nil) @src = src ||= filename && File.read(filename) || '' @filename = filename super end |
Class Method Details
.build(src, filename = nil) ⇒ Object
10 11 12 |
# File 'lib/ruby_cop/node_builder.rb', line 10 def build(src, filename=nil) new(src, filename).parse end |
Instance Method Details
#on_alias(new_name, old_name) ⇒ Object
15 16 17 |
# File 'lib/ruby_cop/node_builder.rb', line 15 def on_alias(new_name, old_name) Ruby::Alias.new(to_ident(new_name), to_ident(old_name)) end |
#on_aref(target, args) ⇒ Object
19 20 21 |
# File 'lib/ruby_cop/node_builder.rb', line 19 def on_aref(target, args) Ruby::Call.new(target, ident(:[]), args) end |
#on_aref_field(target, args) ⇒ Object
23 24 25 |
# File 'lib/ruby_cop/node_builder.rb', line 23 def on_aref_field(target, args) Ruby::Call.new(target, ident(:[]), args) end |
#on_arg_paren(args) ⇒ Object
27 28 29 |
# File 'lib/ruby_cop/node_builder.rb', line 27 def on_arg_paren(args) args end |
#on_args_add(args, arg) ⇒ Object
31 32 33 |
# File 'lib/ruby_cop/node_builder.rb', line 31 def on_args_add(args, arg) args.add(arg); args end |
#on_args_add_block(args, block) ⇒ Object
35 36 37 |
# File 'lib/ruby_cop/node_builder.rb', line 35 def on_args_add_block(args, block) args.add_block(block) if block; args end |
#on_args_new ⇒ Object
39 40 41 |
# File 'lib/ruby_cop/node_builder.rb', line 39 def on_args_new Ruby::Args.new end |
#on_array(args) ⇒ Object
43 44 45 |
# File 'lib/ruby_cop/node_builder.rb', line 43 def on_array(args) args ? args.to_array : Ruby::Array.new end |
#on_assign(lvalue, rvalue) ⇒ Object
47 48 49 |
# File 'lib/ruby_cop/node_builder.rb', line 47 def on_assign(lvalue, rvalue) lvalue.assignment(rvalue, ident(:'=')) end |
#on_assoc_new(key, value) ⇒ Object
51 52 53 |
# File 'lib/ruby_cop/node_builder.rb', line 51 def on_assoc_new(key, value) Ruby::Assoc.new(key, value) end |
#on_assoclist_from_args(args) ⇒ Object
55 56 57 |
# File 'lib/ruby_cop/node_builder.rb', line 55 def on_assoclist_from_args(args) args end |
#on_bare_assoc_hash(assocs) ⇒ Object
59 60 61 |
# File 'lib/ruby_cop/node_builder.rb', line 59 def (assocs) Ruby::Hash.new(assocs) end |
#on_BEGIN(statements) ⇒ Object
63 64 65 |
# File 'lib/ruby_cop/node_builder.rb', line 63 def on_BEGIN(statements) Ruby::Call.new(nil, ident(:BEGIN), nil, statements) end |
#on_begin(body) ⇒ Object
67 68 69 |
# File 'lib/ruby_cop/node_builder.rb', line 67 def on_begin(body) body.is_a?(Ruby::ChainedBlock) ? body : body.to_chained_block end |
#on_binary(lvalue, operator, rvalue) ⇒ Object
71 72 73 |
# File 'lib/ruby_cop/node_builder.rb', line 71 def on_binary(lvalue, operator, rvalue) Ruby::Binary.new(lvalue, rvalue, operator) end |
#on_block_var(params, something) ⇒ Object
79 80 81 |
# File 'lib/ruby_cop/node_builder.rb', line 79 def on_block_var(params, something) params end |
#on_blockarg(arg) ⇒ Object
75 76 77 |
# File 'lib/ruby_cop/node_builder.rb', line 75 def on_blockarg(arg) arg end |
#on_bodystmt(body, rescue_block, else_block, ensure_block) ⇒ Object
83 84 85 86 |
# File 'lib/ruby_cop/node_builder.rb', line 83 def on_bodystmt(body, rescue_block, else_block, ensure_block) statements = [rescue_block, else_block, ensure_block].compact statements.empty? ? body : body.to_chained_block(statements) end |
#on_brace_block(params, statements) ⇒ Object
88 89 90 |
# File 'lib/ruby_cop/node_builder.rb', line 88 def on_brace_block(params, statements) statements.to_block(params) end |
#on_break(args) ⇒ Object
92 93 94 |
# File 'lib/ruby_cop/node_builder.rb', line 92 def on_break(args) Ruby::Call.new(nil, ident(:break), args) end |
#on_call(target, separator, identifier) ⇒ Object
96 97 98 |
# File 'lib/ruby_cop/node_builder.rb', line 96 def on_call(target, separator, identifier) Ruby::Call.new(target, identifier) end |
#on_case(args, when_block) ⇒ Object
100 101 102 |
# File 'lib/ruby_cop/node_builder.rb', line 100 def on_case(args, when_block) Ruby::Case.new(args, when_block) end |
#on_CHAR(token) ⇒ Object
104 105 106 |
# File 'lib/ruby_cop/node_builder.rb', line 104 def on_CHAR(token) Ruby::Char.new(token, position) end |
#on_class(const, superclass, body) ⇒ Object
108 109 110 |
# File 'lib/ruby_cop/node_builder.rb', line 108 def on_class(const, superclass, body) Ruby::Class.new(const, superclass, body) end |
#on_class_name_error(ident) ⇒ Object
112 113 114 |
# File 'lib/ruby_cop/node_builder.rb', line 112 def on_class_name_error(ident) raise SyntaxError, 'class/module name must be CONSTANT' end |
#on_command(identifier, args) ⇒ Object
116 117 118 |
# File 'lib/ruby_cop/node_builder.rb', line 116 def on_command(identifier, args) Ruby::Call.new(nil, identifier, args) end |
#on_command_call(target, separator, identifier, args) ⇒ Object
120 121 122 |
# File 'lib/ruby_cop/node_builder.rb', line 120 def on_command_call(target, separator, identifier, args) Ruby::Call.new(target, identifier, args) end |
#on_const(token) ⇒ Object
124 125 126 |
# File 'lib/ruby_cop/node_builder.rb', line 124 def on_const(token) Ruby::Constant.new(token, position) end |
#on_const_path_field(namespace, const) ⇒ Object
128 129 130 |
# File 'lib/ruby_cop/node_builder.rb', line 128 def on_const_path_field(namespace, const) const.namespace = namespace; const end |
#on_const_path_ref(namespace, const) ⇒ Object
132 133 134 |
# File 'lib/ruby_cop/node_builder.rb', line 132 def on_const_path_ref(namespace, const) const.namespace = namespace; const end |
#on_const_ref(const) ⇒ Object
136 137 138 |
# File 'lib/ruby_cop/node_builder.rb', line 136 def on_const_ref(const) const end |
#on_cvar(token) ⇒ Object
140 141 142 |
# File 'lib/ruby_cop/node_builder.rb', line 140 def on_cvar(token) Ruby::ClassVariable.new(token, position) end |
#on_def(identifier, params, body) ⇒ Object
144 145 146 |
# File 'lib/ruby_cop/node_builder.rb', line 144 def on_def(identifier, params, body) Ruby::Method.new(nil, identifier, params, body) end |
#on_defined(ref) ⇒ Object
152 153 154 |
# File 'lib/ruby_cop/node_builder.rb', line 152 def on_defined(ref) Ruby::Defined.new(ref) end |
#on_defs(target, separator, identifier, params, body) ⇒ Object
148 149 150 |
# File 'lib/ruby_cop/node_builder.rb', line 148 def on_defs(target, separator, identifier, params, body) Ruby::Method.new(target, identifier, params, body) end |
#on_do_block(params, statements) ⇒ Object
156 157 158 |
# File 'lib/ruby_cop/node_builder.rb', line 156 def on_do_block(params, statements) statements.to_block(params) end |
#on_dot2(min, max) ⇒ Object
160 161 162 |
# File 'lib/ruby_cop/node_builder.rb', line 160 def on_dot2(min, max) Ruby::Range.new(min, max, false) end |
#on_dot3(min, max) ⇒ Object
164 165 166 |
# File 'lib/ruby_cop/node_builder.rb', line 164 def on_dot3(min, max) Ruby::Range.new(min, max, true) end |
#on_dyna_symbol(symbol) ⇒ Object
168 169 170 |
# File 'lib/ruby_cop/node_builder.rb', line 168 def on_dyna_symbol(symbol) symbol.to_dyna_symbol end |
#on_else(statements) ⇒ Object
172 173 174 |
# File 'lib/ruby_cop/node_builder.rb', line 172 def on_else(statements) Ruby::Else.new(statements) end |
#on_END(statements) ⇒ Object
176 177 178 |
# File 'lib/ruby_cop/node_builder.rb', line 176 def on_END(statements) Ruby::Call.new(nil, ident(:END), nil, statements) end |
#on_ensure(statements) ⇒ Object
180 181 182 |
# File 'lib/ruby_cop/node_builder.rb', line 180 def on_ensure(statements) statements end |
#on_fcall(identifier) ⇒ Object
197 198 199 |
# File 'lib/ruby_cop/node_builder.rb', line 197 def on_fcall(identifier) Ruby::Call.new(nil, identifier) end |
#on_field(target, separator, identifier) ⇒ Object
201 202 203 |
# File 'lib/ruby_cop/node_builder.rb', line 201 def on_field(target, separator, identifier) Ruby::Call.new(target, identifier) end |
#on_float(token) ⇒ Object
205 206 207 |
# File 'lib/ruby_cop/node_builder.rb', line 205 def on_float(token) Ruby::Float.new(token, position) end |
#on_for(variable, range, statements) ⇒ Object
209 210 211 |
# File 'lib/ruby_cop/node_builder.rb', line 209 def on_for(variable, range, statements) Ruby::For.new(variable, range, statements) end |
#on_gvar(token) ⇒ Object
213 214 215 |
# File 'lib/ruby_cop/node_builder.rb', line 213 def on_gvar(token) Ruby::GlobalVariable.new(token, position) end |
#on_hash(assocs) ⇒ Object
217 218 219 |
# File 'lib/ruby_cop/node_builder.rb', line 217 def on_hash(assocs) Ruby::Hash.new(assocs) end |
#on_ident(token) ⇒ Object
221 222 223 |
# File 'lib/ruby_cop/node_builder.rb', line 221 def on_ident(token) ident(token) end |
#on_if(expression, statements, else_block) ⇒ Object Also known as: on_elsif
184 185 186 |
# File 'lib/ruby_cop/node_builder.rb', line 184 def on_if(expression, statements, else_block) Ruby::If.new(expression, statements, else_block) end |
#on_if_mod(expression, statement) ⇒ Object
193 194 195 |
# File 'lib/ruby_cop/node_builder.rb', line 193 def on_if_mod(expression, statement) Ruby::IfMod.new(expression, statement) end |
#on_ifop(condition, then_part, else_part) ⇒ Object
189 190 191 |
# File 'lib/ruby_cop/node_builder.rb', line 189 def on_ifop(condition, then_part, else_part) Ruby::IfOp.new(condition, then_part, else_part) end |
#on_int(token) ⇒ Object
225 226 227 |
# File 'lib/ruby_cop/node_builder.rb', line 225 def on_int(token) Ruby::Integer.new(token, position) end |
#on_ivar(token) ⇒ Object
229 230 231 |
# File 'lib/ruby_cop/node_builder.rb', line 229 def on_ivar(token) Ruby::InstanceVariable.new(token, position) end |
#on_kw(token) ⇒ Object
233 234 235 |
# File 'lib/ruby_cop/node_builder.rb', line 233 def on_kw(token) Ruby::Keyword.new(token, position) end |
#on_label(token) ⇒ Object
237 238 239 |
# File 'lib/ruby_cop/node_builder.rb', line 237 def on_label(token) Ruby::Label.new(token, position) end |
#on_lambda(params, statements) ⇒ Object
241 242 243 |
# File 'lib/ruby_cop/node_builder.rb', line 241 def on_lambda(params, statements) Ruby::Block.new(statements, params) end |
#on_massign(lvalue, rvalue) ⇒ Object
245 246 247 |
# File 'lib/ruby_cop/node_builder.rb', line 245 def on_massign(lvalue, rvalue) lvalue.assignment(rvalue, ident(:'=')) end |
#on_method_add_arg(call, args) ⇒ Object
249 250 251 |
# File 'lib/ruby_cop/node_builder.rb', line 249 def on_method_add_arg(call, args) call.arguments = args; call end |
#on_method_add_block(call, block) ⇒ Object
253 254 255 |
# File 'lib/ruby_cop/node_builder.rb', line 253 def on_method_add_block(call, block) call.block = block; call end |
#on_mlhs_add(assignment, ref) ⇒ Object
257 258 259 |
# File 'lib/ruby_cop/node_builder.rb', line 257 def on_mlhs_add(assignment, ref) assignment.add(ref); assignment end |
#on_mlhs_add_star(assignment, ref) ⇒ Object
261 262 263 |
# File 'lib/ruby_cop/node_builder.rb', line 261 def on_mlhs_add_star(assignment, ref) assignment.add(Ruby::SplatArg.new(ref)); assignment end |
#on_mlhs_new ⇒ Object
265 266 267 |
# File 'lib/ruby_cop/node_builder.rb', line 265 def on_mlhs_new Ruby::MultiAssignmentList.new end |
#on_module(const, body) ⇒ Object
269 270 271 |
# File 'lib/ruby_cop/node_builder.rb', line 269 def on_module(const, body) Ruby::Module.new(const, body) end |
#on_mrhs_add(assignment, ref) ⇒ Object
273 274 275 |
# File 'lib/ruby_cop/node_builder.rb', line 273 def on_mrhs_add(assignment, ref) assignment.add(ref); assignment end |
#on_mrhs_new_from_args(args) ⇒ Object
277 278 279 |
# File 'lib/ruby_cop/node_builder.rb', line 277 def on_mrhs_new_from_args(args) Ruby::MultiAssignmentList.new(args.elements) end |
#on_next(args) ⇒ Object
281 282 283 |
# File 'lib/ruby_cop/node_builder.rb', line 281 def on_next(args) Ruby::Call.new(nil, ident(:next), args) end |
#on_op(operator) ⇒ Object
285 286 287 |
# File 'lib/ruby_cop/node_builder.rb', line 285 def on_op(operator) operator.intern end |
#on_opassign(lvalue, operator, rvalue) ⇒ Object
289 290 291 |
# File 'lib/ruby_cop/node_builder.rb', line 289 def on_opassign(lvalue, operator, rvalue) lvalue.assignment(rvalue, operator) end |
#on_params(params, optionals, rest, something, block) ⇒ Object
293 294 295 |
# File 'lib/ruby_cop/node_builder.rb', line 293 def on_params(params, optionals, rest, something, block) Ruby::Params.new(params, optionals, rest, block) end |
#on_paren(node) ⇒ Object
297 298 299 |
# File 'lib/ruby_cop/node_builder.rb', line 297 def on_paren(node) node end |
#on_parse_error(message) ⇒ Object
301 302 303 |
# File 'lib/ruby_cop/node_builder.rb', line 301 def on_parse_error() raise SyntaxError, end |
#on_program(statements) ⇒ Object
305 306 307 |
# File 'lib/ruby_cop/node_builder.rb', line 305 def on_program(statements) statements.to_program(@src, @filename) end |
#on_qwords_add(array, word) ⇒ Object
309 310 311 |
# File 'lib/ruby_cop/node_builder.rb', line 309 def on_qwords_add(array, word) array.add(Ruby::String.new(word)); array end |
#on_qwords_new ⇒ Object
313 314 315 |
# File 'lib/ruby_cop/node_builder.rb', line 313 def on_qwords_new Ruby::Array.new end |
#on_redo ⇒ Object
317 318 319 |
# File 'lib/ruby_cop/node_builder.rb', line 317 def on_redo Ruby::Call.new(nil, ident(:redo)) end |
#on_regexp_add(regexp, content) ⇒ Object
321 322 323 |
# File 'lib/ruby_cop/node_builder.rb', line 321 def on_regexp_add(regexp, content) regexp.add(content); regexp end |
#on_regexp_literal(regexp, rdelim) ⇒ Object
325 326 327 |
# File 'lib/ruby_cop/node_builder.rb', line 325 def on_regexp_literal(regexp, rdelim) regexp end |
#on_regexp_new ⇒ Object
329 330 331 |
# File 'lib/ruby_cop/node_builder.rb', line 329 def on_regexp_new Ruby::Regexp.new end |
#on_rescue(types, var, statements, block) ⇒ Object
333 334 335 |
# File 'lib/ruby_cop/node_builder.rb', line 333 def on_rescue(types, var, statements, block) statements.to_chained_block(block, Ruby::RescueParams.new(types, var)) end |
#on_rescue_mod(expression, statements) ⇒ Object
337 338 339 |
# File 'lib/ruby_cop/node_builder.rb', line 337 def on_rescue_mod(expression, statements) Ruby::RescueMod.new(expression, statements) end |
#on_rest_param(param) ⇒ Object
341 342 343 |
# File 'lib/ruby_cop/node_builder.rb', line 341 def on_rest_param(param) param end |
#on_retry ⇒ Object
345 346 347 |
# File 'lib/ruby_cop/node_builder.rb', line 345 def on_retry Ruby::Call.new(nil, ident(:retry)) end |
#on_return(args) ⇒ Object
349 350 351 |
# File 'lib/ruby_cop/node_builder.rb', line 349 def on_return(args) Ruby::Call.new(nil, ident(:return), args) end |
#on_sclass(superclass, body) ⇒ Object
353 354 355 |
# File 'lib/ruby_cop/node_builder.rb', line 353 def on_sclass(superclass, body) Ruby::SingletonClass.new(superclass, body) end |
#on_stmts_add(target, statement) ⇒ Object
357 358 359 |
# File 'lib/ruby_cop/node_builder.rb', line 357 def on_stmts_add(target, statement) target.add(statement) if statement; target end |
#on_stmts_new ⇒ Object
361 362 363 |
# File 'lib/ruby_cop/node_builder.rb', line 361 def on_stmts_new Ruby::Statements.new end |
#on_string_add(string, content) ⇒ Object
365 366 367 |
# File 'lib/ruby_cop/node_builder.rb', line 365 def on_string_add(string, content) string.add(content); string end |
#on_string_concat(*strings) ⇒ Object
369 370 371 |
# File 'lib/ruby_cop/node_builder.rb', line 369 def on_string_concat(*strings) Ruby::StringConcat.new(strings) end |
#on_string_content ⇒ Object
373 374 375 |
# File 'lib/ruby_cop/node_builder.rb', line 373 def on_string_content Ruby::String.new end |
#on_string_dvar(variable) ⇒ Object
weird string syntax that I didn’t know existed until writing this lib. ex. “safe level is #$SAFE” => “safe level is 0”
379 380 381 |
# File 'lib/ruby_cop/node_builder.rb', line 379 def on_string_dvar(variable) variable end |
#on_string_embexpr(expression) ⇒ Object
383 384 385 |
# File 'lib/ruby_cop/node_builder.rb', line 383 def on_string_embexpr(expression) expression end |
#on_string_literal(string) ⇒ Object
387 388 389 |
# File 'lib/ruby_cop/node_builder.rb', line 387 def on_string_literal(string) string end |
#on_super(args) ⇒ Object
391 392 393 |
# File 'lib/ruby_cop/node_builder.rb', line 391 def on_super(args) Ruby::Call.new(nil, ident(:super), args) end |
#on_symbol(token) ⇒ Object
395 396 397 |
# File 'lib/ruby_cop/node_builder.rb', line 395 def on_symbol(token) Ruby::Symbol.new(token, position) end |
#on_symbol_literal(symbol) ⇒ Object
399 400 401 |
# File 'lib/ruby_cop/node_builder.rb', line 399 def on_symbol_literal(symbol) symbol end |
#on_top_const_field(field) ⇒ Object
403 404 405 |
# File 'lib/ruby_cop/node_builder.rb', line 403 def on_top_const_field(field) field end |
#on_top_const_ref(const) ⇒ Object
407 408 409 |
# File 'lib/ruby_cop/node_builder.rb', line 407 def on_top_const_ref(const) const end |
#on_tstring_content(token) ⇒ Object
411 412 413 |
# File 'lib/ruby_cop/node_builder.rb', line 411 def on_tstring_content(token) token end |
#on_unary(operator, operand) ⇒ Object
415 416 417 |
# File 'lib/ruby_cop/node_builder.rb', line 415 def on_unary(operator, operand) Ruby::Unary.new(operator, operand) end |
#on_undef(args) ⇒ Object
419 420 421 |
# File 'lib/ruby_cop/node_builder.rb', line 419 def on_undef(args) Ruby::Call.new(nil, ident(:undef), Ruby::Args.new(args.collect { |e| to_ident(e) })) end |
#on_unless(expression, statements, else_block) ⇒ Object
423 424 425 |
# File 'lib/ruby_cop/node_builder.rb', line 423 def on_unless(expression, statements, else_block) Ruby::Unless.new(expression, statements, else_block) end |
#on_unless_mod(expression, statement) ⇒ Object
427 428 429 |
# File 'lib/ruby_cop/node_builder.rb', line 427 def on_unless_mod(expression, statement) Ruby::UnlessMod.new(expression, statement) end |
#on_until(expression, statements) ⇒ Object
431 432 433 |
# File 'lib/ruby_cop/node_builder.rb', line 431 def on_until(expression, statements) Ruby::Until.new(expression, statements) end |
#on_until_mod(expression, statement) ⇒ Object
435 436 437 |
# File 'lib/ruby_cop/node_builder.rb', line 435 def on_until_mod(expression, statement) Ruby::UntilMod.new(expression, statement) end |
#on_var_alias(new_name, old_name) ⇒ Object
439 440 441 |
# File 'lib/ruby_cop/node_builder.rb', line 439 def on_var_alias(new_name, old_name) Ruby::Alias.new(to_ident(new_name), to_ident(old_name)) end |
#on_var_field(field) ⇒ Object
443 444 445 |
# File 'lib/ruby_cop/node_builder.rb', line 443 def on_var_field(field) field end |
#on_var_ref(ref) ⇒ Object Also known as: on_vcall
447 448 449 |
# File 'lib/ruby_cop/node_builder.rb', line 447 def on_var_ref(ref) ref end |
#on_void_stmt ⇒ Object
453 454 455 |
# File 'lib/ruby_cop/node_builder.rb', line 453 def on_void_stmt nil end |
#on_when(expression, statements, next_block) ⇒ Object
457 458 459 |
# File 'lib/ruby_cop/node_builder.rb', line 457 def on_when(expression, statements, next_block) Ruby::When.new(expression, statements, next_block) end |
#on_while(expression, statements) ⇒ Object
461 462 463 |
# File 'lib/ruby_cop/node_builder.rb', line 461 def on_while(expression, statements) Ruby::While.new(expression, statements) end |
#on_while_mod(expression, statement) ⇒ Object
465 466 467 |
# File 'lib/ruby_cop/node_builder.rb', line 465 def on_while_mod(expression, statement) Ruby::WhileMod.new(expression, statement) end |
#on_word_add(string, word) ⇒ Object
469 470 471 |
# File 'lib/ruby_cop/node_builder.rb', line 469 def on_word_add(string, word) string.add(word); string end |
#on_word_new ⇒ Object
477 478 479 |
# File 'lib/ruby_cop/node_builder.rb', line 477 def on_word_new Ruby::String.new end |
#on_words_add(array, word) ⇒ Object
473 474 475 |
# File 'lib/ruby_cop/node_builder.rb', line 473 def on_words_add(array, word) array.add(word); array end |
#on_words_new ⇒ Object
481 482 483 |
# File 'lib/ruby_cop/node_builder.rb', line 481 def on_words_new Ruby::Array.new end |
#on_xstring_add(string, content) ⇒ Object
485 486 487 |
# File 'lib/ruby_cop/node_builder.rb', line 485 def on_xstring_add(string, content) on_string_add(string, content) end |
#on_xstring_literal(string) ⇒ Object
493 494 495 |
# File 'lib/ruby_cop/node_builder.rb', line 493 def on_xstring_literal(string) string end |
#on_xstring_new ⇒ Object
489 490 491 |
# File 'lib/ruby_cop/node_builder.rb', line 489 def on_xstring_new Ruby::ExecutableString.new end |
#on_yield(args) ⇒ Object
497 498 499 |
# File 'lib/ruby_cop/node_builder.rb', line 497 def on_yield(args) Ruby::Call.new(nil, ident(:yield), args) end |