Skip to content

Instantly share code, notes, and snippets.

@Tho85

Tho85/fill.rb

Created Sep 1, 2011
Embed
What would you like to do?
fill.rb
def fill(&block)
block.call.gsub(/:(\w+)/) { |match| block.binding.eval "(local_variables.include? :#{$1}) ? #{$1} : raise" rescue match }
end
foo = "Hello"
bar = "World"
fill { ":foo :bar :system :exit!" }
# => "Hello world :system :exit!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment