Eloquent Ruby by Russ Olsen
Author:Russ Olsen
Language: eng
Format: epub, pdf
Publisher: Pearson Education Limited (US titles)
Published: 2011-03-16T04:00:00+00:00
Now, as we saw in the last chapter, you can access all of these constants using their fully qualified names by saying things like ErrorCode::OK or ErrorCode::Busy. This can get tedious if you are doing it a lot; if so, you can drop the qualifying module name by simply including the ErrorCode module:
Nothing like being able to insert modules into your class hierarchy to make the workday go faster!
Wrapping Up
In this chapter we have seen how mixin modules solve the problem of code that needs to be shared among classes without using up the one alloted superclass. We have also seen how mixin modules work, how they get drafted into service as a kind of phantom superclass when they are included into a host class. We have also seen that the key issue with mixins is the interface between the host class and the mixin module—what methods does the module provide and what does it expect the class to supply?
For many new Ruby programmers, mixin modules can act as a sort of skeleton key to the whole philosophy behind the language, the elegant way that Ruby tries to help programmers get code to execute where it is needed. Because of this, mixin modules pop up somewhere in most real-world Ruby applications. Nor are we done with them. Mixins will make an encore appearance in Chapter 20 when we look at a slick way to add both instance and class methods to a class with a single include. For now, however, we will turn to the code block, another way of getting code to where you need it.
Download
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
Hello! Python by Anthony Briggs(9919)
OCA Java SE 8 Programmer I Certification Guide by Mala Gupta(9798)
The Mikado Method by Ola Ellnestam Daniel Brolund(9781)
Algorithms of the Intelligent Web by Haralambos Marmanis;Dmitry Babenko(8304)
Sass and Compass in Action by Wynn Netherland Nathan Weizenbaum Chris Eppstein Brandon Mathis(7785)
Test-Driven iOS Development with Swift 4 by Dominik Hauser(7767)
Grails in Action by Glen Smith Peter Ledbrook(7699)
The Well-Grounded Java Developer by Benjamin J. Evans Martijn Verburg(7561)
Windows APT Warfare by Sheng-Hao Ma(6883)
Layered Design for Ruby on Rails Applications by Vladimir Dementyev(6613)
Blueprints Visual Scripting for Unreal Engine 5 - Third Edition by Marcos Romero & Brenden Sewell(6481)
Secrets of the JavaScript Ninja by John Resig Bear Bibeault(6420)
Kotlin in Action by Dmitry Jemerov(5068)
Hands-On Full-Stack Web Development with GraphQL and React by Sebastian Grebe(4320)
Functional Programming in JavaScript by Mantyla Dan(4040)
Solidity Programming Essentials by Ritesh Modi(4027)
WordPress Plugin Development Cookbook by Yannick Lefebvre(3819)
Unity 3D Game Development by Anthony Davis & Travis Baptiste & Russell Craig & Ryan Stunkel(3762)
The Ultimate iOS Interview Playbook by Avi Tsadok(3735)
