Module: ReflectionUtils
- Defined in:
- lib/reflection_utils.rb,
lib/reflection_utils/version.rb,
lib/reflection_utils/create_module_functions.rb,
lib/reflection_utils/create_class_methods_upon_include.rb
Defined Under Namespace
Modules: CreateClassMethodsUponInclude, CreateModuleFunctions
Constant Summary
collapse
- VERSION =
"0.3.0"
Class Method Summary
collapse
Class Method Details
.assert_parameters(proc, parameters) ⇒ Object
26
27
28
29
30
31
32
|
# File 'lib/reflection_utils.rb', line 26
def self.assert_parameters(proc, parameters)
parameters.each_with_index do |parameter, index|
raise ArgumentError, "Argument #{parameter} not found for #{proc} at #{index} index." unless has_parameter?(proc, index, parameter)
end
true
end
|
.call(callback, params = nil) ⇒ Object
14
15
16
|
# File 'lib/reflection_utils.rb', line 14
def self.call(callback, params = nil)
params.nil? ? callback.call : callback.call(params)
end
|
.get_bound_instance_method(instance:, method_name:) ⇒ Object
6
7
8
|
# File 'lib/reflection_utils.rb', line 6
def self.get_bound_instance_method(instance:, method_name:)
get_class_constant(instance: instance).instance_method(method_name).bind(instance)
end
|
.get_class_constant(instance:) ⇒ Object
10
11
12
|
# File 'lib/reflection_utils.rb', line 10
def self.get_class_constant(instance:)
Object.const_get(instance.class.name)
end
|
.has_parameter?(proc, parameter_index, parameter) ⇒ Boolean
34
35
36
|
# File 'lib/reflection_utils.rb', line 34
def self.has_parameter?(proc, parameter_index, parameter)
proc.parameters[parameter_index] == parameter
end
|
.has_parameters?(proc, parameters) ⇒ Boolean
18
19
20
21
22
23
24
|
# File 'lib/reflection_utils.rb', line 18
def self.has_parameters?(proc, parameters)
parameters.each_with_index do |parameter, index|
return false unless has_parameter?(proc, index, parameter)
end
true
end
|
.non_default_class_methods(clazz) ⇒ Object
42
43
44
|
# File 'lib/reflection_utils.rb', line 42
def self.non_default_class_methods(clazz)
clazz.methods - Object.methods
end
|
.non_default_instance_methods(instance) ⇒ Object
46
47
48
|
# File 'lib/reflection_utils.rb', line 46
def self.non_default_instance_methods(instance)
instance.methods - Object.new.methods
end
|
.non_default_methods(class_or_instance) ⇒ Object
38
39
40
|
# File 'lib/reflection_utils.rb', line 38
def self.non_default_methods(class_or_instance)
class_or_instance.is_a?(Module) ? non_default_class_methods(class_or_instance) : non_default_instance_methods(class_or_instance)
end
|