Presentations by Erik Michaels-Ober:
Rails Israel 2015 Conference, Tuesday, November 24, 2015, 09:25
The OpenStruct class was written by Matz in 1998 and has been part of the standard library since Ruby 1.2. The idea behind OpenStruct—a data structure that provides method access to arbitrary attributes—is broadly useful, for example, to interact with API responses or as a test double. However, use of metaprogramming to dynamically define attribute methods at runtime made OpenStruct slow.
I will describe how I was able to optimize OpenStruct to be 10X faster by defining attribute methods lazily. These changes will ship later this year in Ruby 2.3.