Class: Test::Unit::Assertions::RubyReflector::ScopeMethod

Inherits:
Object
  • Object
show all
Defined in:
lib/assert2/rubynode_reflector.rb

Overview

:nodoc:

Instance Method Summary collapse

Instance Method Details

#_scopic(ref, node) ⇒ Object

this is complex because Ruby gloms several different

kinds of variables into one "scope" token, and they
don't directly match their layout in the source code


233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
# File 'lib/assert2/rubynode_reflector.rb', line 233

def _scopic(ref, node)
  @ref        = ref
  @node       = node
  @expression = ''
  @previously = false
  @block_arg  = false
  @splat_arg  = false
  @previous_splat = false
  
  if @node[:tbl]
    @expression << '('
    render_argument_list
    @expression << ')'
  end
  
  @expression << "\n"
  @expression << @ref.next_(@node)
  return @expression
end

#possible_comma(token) ⇒ Object



259
260
261
262
# File 'lib/assert2/rubynode_reflector.rb', line 259

def possible_comma(token)
  @expression << ', ' if @index > 0
  @expression << @ref._send(token)
end

#render_argumentObject



278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
# File 'lib/assert2/rubynode_reflector.rb', line 278

def render_argument
  @splat_arg = @block_arg = false

  if @rest and @rest.first == :lasgn and 
      (@n == nil or @rest.last[:vid] == @n)
    ulterior_comma('*')
    @splat_arg = true
  end

  if @block and (ba = @block[1]) and
      ba.first == :block_arg and ba.last[:vid] == @n
    ulterior_comma('&')
    @block_arg = true
  end

  #  ERGO  Ruby 1.9 changes these rules!!

  if !@previous_splat or @block_arg
    if @opt and @opt.first == :block and #  ERGO  why a @block??
      (lasgn = @opt.last.first).first == :lasgn and
        lasgn.last[:vid] == @n
      @previously = true
      possible_comma(@opt.last.first)
    else
      possible_comma(@n)
      @expression << ' = nil' if @previously and !@block_arg and !@splat_arg
    end

    @previous_splat ||= @splat_arg
  end
end

#render_argument_listObject



264
265
266
267
268
269
270
271
272
273
274
275
276
# File 'lib/assert2/rubynode_reflector.rb', line 264

def render_argument_list
  @nekst = @node[:next]
  @block = @nekst.last       if @nekst && @nekst.first == :block
  @args  = @block.first.last if @block && @block.first.first == :args
  @rest  = @args[:rest]      if @args
  @opt   = @args[:opt]       if @args

  @node[:tbl].each_with_index do |_n, _index|
    @n, @index = _n, _index
    render_argument
    break if @block_arg
  end
end

#ulterior_comma(token) ⇒ Object



253
254
255
256
257
# File 'lib/assert2/rubynode_reflector.rb', line 253

def ulterior_comma(token)
  @expression << ', ' if @index > 0
  @expression << token
  @index = 0
end