Class method
A class method is a method associated with a class rather than a particular instance and invoked through a class or class-related object.
The Well-Grounded Rubyist, Fourth Edition
A class method is a method callable directly on a Ruby class object, including methods defined on that object or inherited by its class.
- How it is used
- Assigns object creation, class-wide utilities, and collective operations to a class rather than an individual instance.
- How deep it goes
- Explains direct definitions, inherited callable methods, receiver distinctions, subclass lookup through singleton classes, and addition through an inclusion callback.
- Examples
- Uses ticket-price comparison, temperature conversion, car statistics, subclass calls, and a module callback.
- What you can do after
- Build it from scratch by defining a method on a class object and choosing that receiver when an instance is inappropriate.
Read how The Well-Grounded Rubyist, Fourth Edition explains class method →
Python How-To
A class method is a method associated with a class that receives the class as its first argument and can access class-level state and behavior.
- How it is used
- Uses class methods mainly as factory methods for creating instances from particular data forms.
- How deep it goes
- Defines @classmethod and cls, demonstrates constructor use, and stops short of deeper implementation internals.
- Examples
- Demonstrates Task construction from dictionaries and text, plus unittest checks for both class methods.
- What you can do after
- Build it from scratch by defining factory methods with @classmethod, cls, and constructor calls, then test them with unittest.
React Quickly, Second Edition
A class method is a function defined as part of a class that can access the class or instance context in which it is invoked.
- How it is used
- Simplifies JSX image rendering and organizes URL-building logic inside a class-based React component.
- How deep it goes
- Distinguishes pure utility methods from instance-dependent methods and compares their functional-component conversions.
- Examples
- Uses an image gallery, getImageSource, image URLs, this.props.index, and equivalent class-to-function implementations.
- What you can do after
- Apply class methods to simplify JSX and convert them into pure or local functions when building functional components.
Read how React Quickly, Second Edition explains class method →
Related concepts
- inheritedincludes · inherited is a Ruby class method callback invoked on a class when that class is subclassed, receiving the new subclass as its argument.
- extendproduced by · extend is a Ruby method that adds the instance methods of one or more modules to a particular object's singleton class.
These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.


