Skip to content

Instantly share code, notes, and snippets.

@sontek
Created October 31, 2011 07:11
Show Gist options
  • Save sontek/1327060 to your computer and use it in GitHub Desktop.
Save sontek/1327060 to your computer and use it in GitHub Desktop.
Crazy ass ruby string interpolation by zedshaw
# 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