Module: Bade::Where
- Defined in:
- lib/bade/runtime/utils/where.rb
Class Method Summary collapse
- .class?(klass) ⇒ [String, Integer], String
-
.class_primarily?(klass) ⇒ Boolean
Raises ArgumentError if klass does not have any Ruby methods defined in it.
- .instance_method?(klass, method_name) ⇒ [String, Integer], String
- .instance_methods?(klass, method_name) ⇒ Boolean
- .method?(klass, method_name) ⇒ [String, Integer], String
- .methods?(klass, method_name) ⇒ Boolean
- .proc?(proc) ⇒ [String, Integer], String
Class Method Details
.class?(klass) ⇒ [String, Integer], String
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/bade/runtime/utils/where.rb', line 38 def class?(klass) defined_methods(klass) .group_by { |sl| sl[0] } .map do |file, sls| lines = sls.map { |sl| sl[1] } { file: file, count: lines.size, line: lines.min, } end # rubocop:disable Style/MultilineBlockChain .sort_by { |fc| fc[:count] } .map { |fc| [fc[:file], fc[:line]] } end |
.class_primarily?(klass) ⇒ Boolean
Raises ArgumentError if klass does not have any Ruby methods defined in it.
55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/bade/runtime/utils/where.rb', line 55 def class_primarily?(klass) source_locations = class?(klass) if source_locations.empty? methods = defined_methods(klass) msg = if methods.empty? "#{klass} has no methods" else "#{klass} only has built-in methods (#{methods.size} in total)" end raise ::ArgumentError, msg end source_locations[0] end |
.instance_method?(klass, method_name) ⇒ [String, Integer], String
24 25 26 |
# File 'lib/bade/runtime/utils/where.rb', line 24 def instance_method?(klass, method_name) source_location(klass.instance_method(method_name)) end |
.instance_methods?(klass, method_name) ⇒ Boolean
32 33 34 |
# File 'lib/bade/runtime/utils/where.rb', line 32 def instance_methods?(klass, method_name) via_extractor?(:method, klass, method_name) end |
.method?(klass, method_name) ⇒ [String, Integer], String
17 18 19 |
# File 'lib/bade/runtime/utils/where.rb', line 17 def method?(klass, method_name) source_location(klass.method(method_name)) end |
.methods?(klass, method_name) ⇒ Boolean
28 29 30 |
# File 'lib/bade/runtime/utils/where.rb', line 28 def methods?(klass, method_name) via_extractor?(:method, klass, method_name) end |