Created
October 31, 2011 07:11
-
-
Save sontek/1327060 to your computer and use it in GitHub Desktop.
Crazy ass ruby string interpolation by zedshaw
This file contains 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
# Ruby style string interpolation with a giant bag of evil python. | |
import inspect | |
class __(str): | |
def __init__(self, other): | |
super(__, self).__init__(other) | |
def __invert__(self): | |
frame = inspect.currentframe() | |
try: | |
return self.format(**frame.f_back.f_locals) | |
finally: | |
del frame | |
style = "Science" | |
x = __("fuck yeah! {style}") | |
print ~x | |
style = "Hard Core Rap" | |
print ~x | |
style = "Fucking Evil" | |
print ~x | |
def test_that_shit(fmt): | |
style = "Smooth Butta" | |
return ~fmt | |
print test_that_shit(x) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment