+ 9

What is the difference between 'extend' and 'include' in ruby?

20th May 2018, 1:55 PM
Prabhat
Prabhat - avatar
2 Answers
+ 2
" ... include is the most common way of importing external code into a class ... Include include is the most used and the simplest way of importing module code. When calling it in a class definition, Ruby will insert the module into the ancestors chain of the class, just after its superclass.  ... Extend On the other end, using extend on a class will actually import the module methods as class methods. ... " Source : ( code examples included showing implementation ) https://medium.com/@leo_hetsch/ruby-modules-include-vs-prepend-vs-extend-f09837a5b073
20th May 2018, 2:07 PM
Rahul George
Rahul George - avatar
+ 2
Extending is using a preexisting class or methods library and tapping into its resources to perform futher functionality. Include is importing a library or class type INTO the programming. Its same with Java and C++ except they use #include in C++ when its import in Java. The terminology may be slightly diff but concept and actions performed are same.
21st May 2018, 4:53 PM
Apple Blossom
Apple Blossom - avatar