Skip to content

Instantly share code, notes, and snippets.

@betawaffle
Created March 25, 2012 15:19
Show Gist options
  • Save betawaffle/2197223 to your computer and use it in GitHub Desktop.
Save betawaffle/2197223 to your computer and use it in GitHub Desktop.
class FormattedString < String
PATTERN = /:(\w+)/
DEFER = lambda { |match| match }
def initialize str = '', pattern = nil
super str
pattern ||= PATTERN
@compiler = DEFER
@orig = str
@gsub = gsub! pattern
end
def compiler &block
@compiler = block if block
@compiler
end
def compiler= block
@compiler = block || DEFER
end
def compile!
@gsub.each &compiler
end
def revert!
replace @orig
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment