Ruby Metaprogramming Aha!

At the recommendation of Joe O’Brien, I watched Dave Thomas’ fantastic bottom-up explanation of Metaprogramming in Ruby.

The talk provides a very lucid explanation of a lot of Ruby (and Rails) magic that always gets glossed over in any intro to ruby kind of talk. It’s kind of the same way I never really *got* certain concepts until I made my 9th grade teacher completely show me Proof By Induction.

Anyway, I highly recommend it for any computer-science curious types.
It crescendos to wonderful payoff where this piece of code makes complete sense:

class Class
	def meta
		class << self
			self
		end
	end
end

class Dave

	class << self
		def self.hi
			puts "WHATS UP META!"
		end
	end

end

Dave.meta.hi

Related posts:

  1. Last Facebook Ruby Code – Grids
  2. 7 reasons I switched back to PHP after 2 years on Rails – O'Reilly Ruby
  3. Rails vs. PHP, or why I like method_missing
  4. Google Talk
  5. It’s all been done before, yet here’s my soution to the Mike Korn facebook puzzle
posted on Friday, June 27th, 2008 by kremdela in Personal

0 Comments

Leave Comment