Comprehensive Guide to Modules in Ruby 3
Ғылым және технология
Ruby modules can appear to be very similar to Ruby classes. After going through this you'll be able to:
- Understand the difference between Classes and Modules in Ruby
- Build out Ruby modules
- Work with nested modules
- Combine Classes and Modules
- See how modules can be used in large-scale, production Rails applications
Source code:
github.com/jordanhudgens/ruby...
Пікірлер: 16
seriously some of the best teaching on ruby I've found. So thankful
Thanks for explaining the ruby nested stuff, it's been very helpful to try and understand it. Something I didn't know Ruby had was anonymous classes which is pretty interesting and cool. Great video and great explanation.
Is the reason for adding the nested class so you can create private methods? I can't really see what value the nested class adds other than being able to make methods private. If you didn't need the private method would it work to just define the function in the nested modules directly and skip the nested class or is the nested class important for some other aspect that I'm not understanding?
I don't understand why you used a class like that inside a module. What would be different if you created an actual class?
Thank you, Jordan for the great explanation! First I have got "private method `tax_rate' called for Sale::FormBuilder:Module (NoMethodError)" since I had ruby 2.6.0 version After update to 3.0.1, it starts working
@edutechional
3 жыл бұрын
Nice job working through it, and yes, this implementation is specific to Ruby 3
Jordan, this is a really helpful example that made me thought a couple of places where I can implement this in my project. Thanks for sharing! I was wondering, how do you run Ruby inside VIM?
Thank for Teaching
Would be helpful to explain what advantages does it have to extract code to modules(and then define an anonymous class inside them) over extracting code to classes.
thank you.
Nice. Manipulating classes and making data available between them is one of the difficult things in ruby. This example will work for Ruby 2 as well, wont it ?
@edutechional
3 жыл бұрын
I'm glad that you found it helpful! And yes, this is the same syntax for 2 and 3
I don't get any results
this did not make sense to me at all unfortunately
Using expressions like 'self.method' is pointless (in general at least) in ruby as it is equivalent to 'method'. It just makes it very confusing. Also you never actually explain the difference between a class and a module.
@jake9340
5 ай бұрын
No actually "def self.method" means it is a class method while "def method" is an instance method