Talks
Speakers
Events
Topics
Sign in
Home
Talks
Speakers
Events
Topics
Leaderboard
Use
Analytics
Sign in
Suggest modification to this talk
Title
Description
How can we write classes that are easy to understand? How can we write Ruby in a declarative way? How can we use metaprogramming without introducing chaos? Come learn the magic behind the first bit of metaprogramming we all encounter with Ruby - attr_reader. From there, we can learn how different gems use class macros to simplify our code. Finally, we’ll explore multiple ways we can make our own class macros to make our codebase easier to read and extend.
Date
Summarized using AI?
If this talk's summary was generated by AI, please check this box. A "Summarized using AI" badge will be displayed in the summary tab to indicate that the summary was generated using AI.
Show "Summarized using AI" badge on summary page
Summary
Markdown supported
In the talk titled "Declare Victory with Class Macros," Jess Hottenstein explores the concept of class macros in Ruby, aiming to enhance code readability and extensibility through metaprogramming techniques while avoiding complexity. She begins by introducing herself and her background, sharing her journey with Ruby since 2009 and her involvement with Splitwise, where a team of developers create a product that helps manage financial relationships. The session outlines several key points: - **Definition of Class Macros**: Class macros are methods defined on a class that can create or manipulate instance methods, facilitating easier code management. Hottenstein exemplifies this with `attr_reader`, which enables object attribute access. - **Understanding `attr_reader`**: Using the Greeter class, she explains how `attr_reader :name` functions as a method generator to create accessors for instance variables, showcasing Ruby's object-oriented nature. - **Exploration of Metaprogramming**: Hottenstein discusses how class macros can be employed to expand functionality and include methods dynamically as needed, emphasizing the balance between usability and functionality. - **Caching Techniques**: Caching is illustrated through the example of memoization. She relates this to a gem created by a developer at Panorama, explaining its performance benefits by storing method outcomes to reduce computation time. - **Hook Methods**: The implementation of hook methods is presented as a means to manage method behaviors upon inclusion in other contexts, providing flexibility in code design and functionality. - **Creating a `cachable` Macro**: The practical implementation of a `cachable` class macro is covered, focusing on inter-method references and ensuring that both cached and non-cached operations function correctly. - **Community Engagement**: Hottenstein encourages the Ruby community to participate in discussions and share knowledge, closing with a reminder of the enriching experience fostered by collaborative learning. In conclusion, Hottenstein emphasizes that mastering class macros can significantly enhance a developer's ability to manipulate Ruby's syntax to create clean, readable, and purposeful code. She directs attendees interested in further exploration to a related `cachable` gem for more practical examples and insights, and is grateful for the community's collective knowledge shared throughout the conference.
Suggest modifications
Cancel