Skip to content

Instantly share code, notes, and snippets.

@pmarreck
Created February 23, 2011 04:36
Show Gist options
  • Save pmarreck/840028 to your computer and use it in GitHub Desktop.
Save pmarreck/840028 to your computer and use it in GitHub Desktop.
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