Skip to content

Instantly share code, notes, and snippets.

@richo
Created February 10, 2012 14:22
Show Gist options
  • Save richo/1789886 to your computer and use it in GitHub Desktop.
Save richo/1789886 to your computer and use it in GitHub Desktop.
Blog post comparing ruby to python
class Iter(object):
def __init__(self):
self.count = 0
self.final = 10
def __iter__(self):
return self
def next(self):
if self.count == self.final:
raise StopIteration
else:
return self.count
self.count += 1
class Iter
def initialize
@max = 10
end
def each
count = 0
until count == @max
yield count
count += 1
end
end
end
class Thing:
def __init__(self):
self.data = get_blocking_data
def get_data(self, key):
return self.data[key]
class Thing
def get_data(key)
data[key]
end
def data
@data ||= get_blocking_data
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment