Guest User

Untitled

a guest
Jul 17th, 2018
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.87 KB | None | 0 0
  1.  
  2. Ken Collins <ken@metaskills.net>
  3.  
  4. In the last case where you opened up the classs. Poor form? What
  5. about the ability to reflect on how a class is extended? For instance
  6. ActiveRecord::Base.included_modules and/or ActiveRecord::Base.extended_by.
  7. Opening up classes looks the ability for reflection to how it was changed.
  8.  
  9. Here is a snippet of code below to expand on my point. I just found out
  10. that the class method extended_by comes from ActiveSupport (I think) but
  11. it's not vanilla ruby. So maybe this is where the pattern evolved. IE,
  12. by using included and letting include do the extend, we are able to reflect
  13. on how us/others have extended the class. Which is funny, because the
  14. english of it should be allowed. Hence is there a default Ruby way to
  15. reflect on extended?
  16.  
  17. All of what your saying might make sense for one’s own lib and code
  18. organization. Like for instance, the author of ActiveRecord might
  19. just follow your simple pattern at the top and by the time I load up
  20. ActiveRecord::Base and asks for it’s included modules, I get a clean
  21. slate of [Kernel] which makes the default idiom (which yes does not
  22. match english) work. Thoughts?
  23.  
  24.  
  25.  
  26. class SomebodyElsesLib
  27.  
  28. end
  29.  
  30. module MetaSkills
  31. module KillerFeature
  32.  
  33. def self.inlcuded(klass)
  34. klass.class_eval do
  35. extend ClassMethods
  36. include InstanceMethods
  37. end
  38. end
  39.  
  40. module InstanceMethods
  41.  
  42. def killa_instance
  43. 'instance'
  44. end
  45.  
  46. end
  47.  
  48. module ClassMethods
  49.  
  50. def acts_as_killa
  51. 'class'
  52. end
  53.  
  54. end
  55.  
  56. end
  57. end
  58.  
  59. SomebodyElsesLib.send :include, MetaSkills::KillerFeature
  60.  
  61. SomebodyElsesLib.included_modules # => [MetaSkills::KillerFeature, Kernel]
  62. SomebodyElsesLib.extended_by # ~> -:40: undefined method `extended_by' for SomebodyElsesLib:Class (NoMethodError)
Add Comment
Please, Sign In to add comment