Module: Where

Defined in:
lib/where_is.rb,
lib/where_is/version.rb

Constant Summary collapse

VERSION =
'0.3.1'.freeze

Class Method Summary collapse

Class Method Details

.are(klass, method = nil) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
# File 'lib/where_is.rb', line 17

def are(klass, method = nil)
  if method
    begin
      Where.are_instance_methods(klass, method)
    rescue NameError
      Where.are_methods(klass, method)
    end
  else
    Where.is_class(klass)
  end
end

.are_instance_methods(klass, method_name) ⇒ Object



52
53
54
55
56
57
58
59
60
61
# File 'lib/where_is.rb', line 52

def are_instance_methods(klass, method_name)
  methods = are_via_extractor(:instance_method, klass, method_name)
  source_locations = group_and_combine_source_locations(methods)

  if source_locations.empty?
    raise NameError, "#{klass} has no methods called #{method_name}"
  end

  source_locations
end

.are_methods(klass, method_name) ⇒ Object



41
42
43
44
45
46
47
48
49
50
# File 'lib/where_is.rb', line 41

def are_methods(klass, method_name)
  methods = are_via_extractor(:method, klass, method_name)
  source_locations = group_and_combine_source_locations(methods)

  if source_locations.empty?
    raise NameError, "#{klass} has no methods called #{method_name}"
  end

  source_locations
end

.is(klass, method = nil) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
# File 'lib/where_is.rb', line 5

def is(klass, method = nil)
  if method
    begin
      Where.is_instance_method(klass, method)
    rescue NameError
      Where.is_method(klass, method)
    end
  else
    Where.is_class_primarily(klass)
  end
end

.is_class(klass) ⇒ Object



63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/where_is.rb', line 63

def is_class(klass)
  methods = defined_methods(klass)
  source_locations = group_and_combine_source_locations(methods)

  if source_locations.empty?
    raise NameError, "#{klass} has no methods" if methods.empty?
    raise NameError, "#{klass} only has built-in methods " \
                         "(#{methods.size} in total)"
  end

  source_locations
end

.is_class_primarily(klass) ⇒ Object



76
77
78
# File 'lib/where_is.rb', line 76

def is_class_primarily(klass)
  is_class(klass)[0]
end

.is_instance_method(klass, method_name) ⇒ Object



37
38
39
# File 'lib/where_is.rb', line 37

def is_instance_method(klass, method_name)
  source_location(klass.instance_method(method_name))
end

.is_method(klass, method_name) ⇒ Object



33
34
35
# File 'lib/where_is.rb', line 33

def is_method(klass, method_name)
  source_location(klass.method(method_name))
end

.is_proc(proc) ⇒ Object



29
30
31
# File 'lib/where_is.rb', line 29

def is_proc(proc)
  source_location(proc)
end