~/talk

Metaprogramming: Unraveling the Magic

Talkat RubyConf India 2024 · 2024-11-29..11-30· [ruby-on-rails, ruby]
slides:none on file

Live code shows how Rails-style metaprogramming actually generates methods at runtime: reopening String to implement a working titleize that capitalizes words, using define_method to create enum predicates that return true for admin, and using public_send to dispatch add/subtract calls dynamically. Demos expose singleton methods stored in an eigenclass (class methods via metaclass), instance-level access via instance_eval, and class-level changes via class_eval (Rails uses this for concerns and scopes); undefined-method examples produce the expected errors.

AI-written summary · about

  1. 0:00Introduction and welcome
  2. 1:59What is metaprogramming
  3. 3:03Metaprogramming in Ruby
  4. 4:08Open classes and monkey patching
  5. 6:19Method missing and dynamic methods
  6. 7:49Dynamic method dispatch
  7. 9:26Using send method
  8. 10:09Singleton methods
  9. 11:34Metaclasses and n-classes
  10. 12:22Defining class methods
  11. 12:43Mimic methods like attr_accessor
  12. 13:25Hook methods and lifecycle
  13. 14:56Accessing instance variables
  14. 15:44Class eval and open classes
  15. 16:58Cherry picking methods
  16. 17:46Method missing as a fallback
  17. 18:12Closing and thanks
~/search
type to search 6,249 conferences, 138,987 speakers and 185,172 talks
~/help
cmdctrl k
search every conference, speaker and series
/
focus the filter search
h
home
c
conferences
s
speakers
e
series
t
light / dark — the status bar button does the same
?
this help
esc
close this, then clear every filter — or just the search, while you are typing in it

Ignored while you are typing. Pages without a filter rail have no search to focus.