Class: Surrogate::SurrogateClassReflector
- Inherits:
-
Struct
- Object
- Struct
- Surrogate::SurrogateClassReflector
- Defined in:
- lib/surrogate/surrogate_class_reflector.rb
Overview
Reflects on the surrogate class to give info about methods that are useful for the comparer
It might make sense to not treat instance and class differently, but instead let whoever wants to use this instantiate it with both the class and the singleton class.
Instance Attribute Summary collapse
-
#surrogate_class ⇒ Object
Returns the value of attribute surrogate_class.
Instance Method Summary collapse
- #class_api_methods ⇒ Object
- #class_hatchery ⇒ Object
- #class_inherited_methods ⇒ Object
- #class_other_methods ⇒ Object
- #class_without_bodies ⇒ Object
- #instance_api_methods ⇒ Object
- #instance_inherited_methods ⇒ Object
- #instance_other_methods ⇒ Object
- #instance_without_bodies ⇒ Object
- #methods ⇒ Object
- #singleton_class_hatchery ⇒ Object
Instance Attribute Details
#surrogate_class ⇒ Object
Returns the value of attribute surrogate_class
8 9 10 |
# File 'lib/surrogate/surrogate_class_reflector.rb', line 8 def surrogate_class @surrogate_class end |
Instance Method Details
#class_api_methods ⇒ Object
41 42 43 |
# File 'lib/surrogate/surrogate_class_reflector.rb', line 41 def class_api_methods Set.new singleton_class_hatchery.api_method_names end |
#class_hatchery ⇒ Object
57 58 59 |
# File 'lib/surrogate/surrogate_class_reflector.rb', line 57 def class_hatchery @class_hatchery ||= surrogate_class.instance_variable_get :@hatchery end |
#class_inherited_methods ⇒ Object
45 46 47 |
# File 'lib/surrogate/surrogate_class_reflector.rb', line 45 def class_inherited_methods Set.new surrogate_class.singleton_class.instance_methods - surrogate_class.singleton_class.instance_methods(false) end |
#class_other_methods ⇒ Object
49 50 51 |
# File 'lib/surrogate/surrogate_class_reflector.rb', line 49 def class_other_methods Set.new(surrogate_class.singleton_class.instance_methods false) - class_api_methods - class_inherited_methods end |
#class_without_bodies ⇒ Object
53 54 55 |
# File 'lib/surrogate/surrogate_class_reflector.rb', line 53 def class_without_bodies Set.new singleton_class_hatchery.api_method_names.reject { |name| singleton_class_hatchery.api_method_for name } end |
#instance_api_methods ⇒ Object
25 26 27 |
# File 'lib/surrogate/surrogate_class_reflector.rb', line 25 def instance_api_methods Set.new class_hatchery.api_method_names end |
#instance_inherited_methods ⇒ Object
29 30 31 |
# File 'lib/surrogate/surrogate_class_reflector.rb', line 29 def instance_inherited_methods Set.new surrogate_class.instance_methods - surrogate_class.instance_methods(false) end |
#instance_other_methods ⇒ Object
33 34 35 |
# File 'lib/surrogate/surrogate_class_reflector.rb', line 33 def instance_other_methods Set.new(surrogate_class.instance_methods false) - instance_api_methods end |
#instance_without_bodies ⇒ Object
37 38 39 |
# File 'lib/surrogate/surrogate_class_reflector.rb', line 37 def instance_without_bodies Set.new class_hatchery.api_method_names.reject { |name| class_hatchery.api_method_for name } end |
#methods ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/surrogate/surrogate_class_reflector.rb', line 9 def methods { instance: { api: instance_api_methods, inherited: instance_inherited_methods, other: instance_other_methods, without_bodies: instance_without_bodies, }, class: { api: class_api_methods, inherited: class_inherited_methods, other: class_other_methods, without_bodies: class_without_bodies, }, } end |
#singleton_class_hatchery ⇒ Object
61 62 63 |
# File 'lib/surrogate/surrogate_class_reflector.rb', line 61 def singleton_class_hatchery @singleton_class_hatchery ||= surrogate_class.singleton_class.instance_variable_get :@hatchery end |