News Score: Score the News, Sort the News, Rewrite the Headlines

Metaprogramming in Ruby: It's All About the Self

After writing my last post on Rails plugin idioms, I realized that Ruby metaprogramming, at its core, is actually quite simple. It comes down to the fact that all Ruby code is executed code--there is no separate compile or runtime phase. In Ruby, every line of code is executed against a particular self. Consider the following five snippets: class Person def self.species "Homo Sapien" end end class Person class << self def species "Homo Sapien" end end end class << Person def species "Homo Sapien...

Read more at yehudakatz.com

© News Score  score the news, sort the news, rewrite the headlines