Class: Mrubyc::Test::Generator::Double

Inherits:
Object
  • Object
show all
Defined in:
lib/mrubyc/test/generator/double.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type, object, location) ⇒ Double

Returns a new instance of Double.



13
14
15
16
17
# File 'lib/mrubyc/test/generator/double.rb', line 13

def initialize(type, object, location)
  @type = type
  @klass = object.class == Class ? object : object.class
  @location = location
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/mrubyc/test/generator/double.rb', line 19

def method_missing(method_name, *args)
  param_size = args[0] || 0
  @@double_method_locations << {
    type: @type,
    class: @klass,
    method_name: method_name,
    args: args.to_s,
    method_parameters: Array.new(param_size).map.with_index{|_, i| ('a'.ord + i).chr }.join(','),
    block: (block_given? ? yield : nil),
    label: @location.label,
    path: @location.absolute_path || @location.path,
    line: @location.lineno
  }
end

Class Method Details

.init_double_method_locationsObject



8
9
10
# File 'lib/mrubyc/test/generator/double.rb', line 8

def init_double_method_locations
  @@double_method_locations = []
end