Class: TRuby::CodeEmitter::Ruby40

Inherits:
Ruby34 show all
Defined in:
lib/t_ruby/code_emitter.rb

Overview

Ruby 4.0+ emitter - _1 raises NameError, must use ‘it`

Instance Attribute Summary

Attributes inherited from Base

#version

Instance Method Summary collapse

Methods inherited from Ruby34

#supports_it?

Methods inherited from Ruby31

#transform_block_forwarding

Methods inherited from Base

#initialize, #supports_it?, #transform, #transform_block_forwarding

Constructor Details

This class inherits a constructor from TRuby::CodeEmitter::Base

Instance Method Details

#numbered_params_error?Boolean

Returns:

  • (Boolean)


173
174
175
# File 'lib/t_ruby/code_emitter.rb', line 173

def numbered_params_error?
  true
end

#transform_numbered_params(source) ⇒ Object

Transform numbered parameters to appropriate syntax

  • Single _1 → it

  • Multiple (_1, _2) → explicit |k, v| params



181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
# File 'lib/t_ruby/code_emitter.rb', line 181

def transform_numbered_params(source)
  result = source.dup

  # Simple approach: replace all _1 with it when it's the only numbered param in scope
  # For complex cases with _2+, we'd need proper parsing
  # For now, do a global replacement if _2 etc are not present
  if result.match?(/\b_[2-9]\b/)
    # Has multiple numbered params - need to convert to explicit params
    # This is a complex case that requires proper block parsing
    transform_multi_numbered_params(result)
  else
    # Only _1 is used - simple replacement
    result.gsub(/\b_1\b/, "it")
  end
end