Created
October 22, 2010 23:06
-
-
Save tenderlove/641534 to your computer and use it in GitHub Desktop.
itr.rb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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