Ruby Metaprogramming Series: Ep3 : Monkey Patching

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] hi today we are going to talk about notorious ruby technique known as monkey-patching well as we all have known that open classes are pretty useful feature but there are some side effects when you overuse or revisit monkey-patching is a technique to add modify or suppress the default behavior of a piece of code at runtime without changing its original source code also this feature is mainly used by gym or library writers to add features to Ruby's core classes here is an example use case let's assume we want to replace a value in an array with something else instead of writing this code every time we create a helper method and use it from every part of the application let's try if this matter really works if it really places the item in the array looks like it works Hey since the example works we wish to make it more easier to use from the application scope so we decide to open the era class and add the method within nice it works yeah you define your matter but you didn't realize that there is a matter named replace defined already in the era class and their behavior is completely different your method replaces an element while the other replaces the whole array so this is the disadvantage of using the monkey-patching technique in Ruby this is why one must be very careful while opening core library classes like a string Aryan has we were laying with this design in such a way that any method you need is often already defined and ready to use I would recommend you to go through all the methods and cool librarians in the website and this will help you to write better efficient code and be a better software developer Thanks this must for this episode see you in the next episode
Info
Channel: ROR Consultant
Views: 238
Rating: undefined out of 5
Keywords: ruby, tutorial, meta programming, advanced-ruby, openclass
Id: j_GKXqu93qU
Channel Id: undefined
Length: 4min 32sec (272 seconds)
Published: Fri Dec 27 2019
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.