Exception: RubyLess::NoMethodError

Inherits:
Error
  • Object
show all
Defined in:
lib/ruby_less/no_method_error.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(receiver, klass, signature) ⇒ NoMethodError

Returns a new instance of NoMethodError.



5
6
7
8
9
# File 'lib/ruby_less/no_method_error.rb', line 5

def initialize(receiver, klass, signature)
  @receiver = receiver
  @klass = klass
  @signature = signature
end

Instance Attribute Details

#klassObject (readonly)

Returns the value of attribute klass.



3
4
5
# File 'lib/ruby_less/no_method_error.rb', line 3

def klass
  @klass
end

#receiverObject (readonly)

Returns the value of attribute receiver.



3
4
5
# File 'lib/ruby_less/no_method_error.rb', line 3

def receiver
  @receiver
end

#signatureObject (readonly)

Returns the value of attribute signature.



3
4
5
# File 'lib/ruby_less/no_method_error.rb', line 3

def signature
  @signature
end

Instance Method Details

#error_messageObject



15
16
17
18
19
20
21
# File 'lib/ruby_less/no_method_error.rb', line 15

def error_message
  if ivar?
    "unknown instance variable"
  else
    "unknown method"
  end
end

#ivar?Boolean

Returns:



43
44
45
# File 'lib/ruby_less/no_method_error.rb', line 43

def ivar?
  @signature.first =~ /\A@/
end

#messageObject



11
12
13
# File 'lib/ruby_less/no_method_error.rb', line 11

def message
  "#{error_message} '#{method_with_arguments}' for #{receiver_with_class}."
end

#method_with_argumentsObject



28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/ruby_less/no_method_error.rb', line 28

def method_with_arguments
  method = @signature.first
  signature = @signature[1..-1]
  return method if ivar?
  if signature.size == 0
    arguments = ''
  else
    arguments = signature.map{|s| s.kind_of?(Class) ? s.to_s : s.inspect}.join(', ')
    if signature.size == 1 && (signature.first.kind_of?(Array) || signature.first.kind_of?(Hash))
      arguments = arguments[1..-2]
    end
  end
  "#{method}(#{arguments})"
end

#receiver_with_classObject



23
24
25
26
# File 'lib/ruby_less/no_method_error.rb', line 23

def receiver_with_class
  klass = @klass.kind_of?(Class) ? @klass : @klass.class
  @receiver ? "'#{@receiver}' of type #{@klass}" : klass
end