Created
February 23, 2011 04:36
-
-
Save pmarreck/840028 to your computer and use it in GitHub Desktop.
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
require 'sender' | |
# For fun, trying to define my own string interpolator so that any symbol in a string (optionally end-delimited with a colon if not at a word boundary) gets substituted for its eval'd value. | |
# Here's what I have so far. No workie, due to context issue with "eval" call. Help? | |
class String | |
def i | |
self.gsub(/:([\w_]+)/){|match| __sender__.eval $1} | |
end | |
end | |
t = 4 | |
abba = 6 | |
system = "systema" | |
puts "this is a :t of the :abba :system.".i |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment