Project

General

Profile

Feature #14111 » argument_error.rb

esjee (SJ Stoker), 06/25/2018 09:10 PM

 
1
module PrintPrototype
2
  prepend_features ArgumentError
3

    
4
  def to_s
5
    msg = super.dup
6

    
7
    parameters = receiver.method(method_name).parameters
8

    
9
    human_friendly_parameters = parameters.map do |type, name|
10
      # type is one of
11
      # req
12
      # opt
13
      # rest
14
      # key
15
      # keyreq
16
      # keyrest
17
      # block
18

    
19
      human_friendly_type = case type
20
      when :req
21
        "required"
22
      when :opt
23
        "optional"
24
      when :rest
25
        "rest"
26
      when :key
27
        "optional keyword"
28
      when :keyreq
29
        "required keyword"
30
      when :keyrest
31
        "rest keyword"
32
      when :block
33
        "block"
34
      else
35
        type.to_s
36
      end
37

    
38
      "\t#{name} (#{human_friendly_type})"
39
    end
40

    
41
    if human_friendly_parameters.any?
42
      msg << "\n\nMethod parameters:\n#{human_friendly_parameters.join "\n"}"
43
    end
44

    
45
  rescue => _e
46
    puts _e
47
    super
48
  end
49
end