Created
February 10, 2012 14:22
-
-
Save richo/1789886 to your computer and use it in GitHub Desktop.
Blog post comparing ruby to python
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 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 | |
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 Iter | |
def initialize | |
@max = 10 | |
end | |
def each | |
count = 0 | |
until count == @max | |
yield count | |
count += 1 | |
end | |
end | |
end |
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 Thing: | |
def __init__(self): | |
self.data = get_blocking_data | |
def get_data(self, key): | |
return self.data[key] |
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 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