Skip to content

Instantly share code, notes, and snippets.

@tenderlove
Created October 22, 2010 23:06
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tenderlove/641534 to your computer and use it in GitHub Desktop.
Save tenderlove/641534 to your computer and use it in GitHub Desktop.
itr.rb
class Metaclass
include Enumerable
def initialize obj
@obj = obj
end
def each
return enum_for(:each) unless block_given?
x = meta_for @obj
loop do
yield x
x = meta_for x
end
end
private
def meta_for o
class << o; self; end
end
end
x = Metaclass.new Object.new
p x.first(10) # first 10 metaclasses
itr = x.each
10.times do
p itr.next
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment