Skip to content

Instantly share code, notes, and snippets.

@tenderlove

tenderlove/itr.rb

Created Oct 22, 2010
Embed
What would you like to do?
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