Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
# This relates to the issue described at:
# https://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/4709
class String
def %(args)
if args.kind_of?(Hash)
dup.gsub(INTERPOLATION_PATTERN_WITH_ESCAPE) do |match|
if match == '%%'
'%'
else
key = ($1 || $2).to_sym
raise KeyError unless args.has_key?(key)
$3 ? sprintf("%#{$3}", args[key]) : args[key]
end
end
elsif self =~ INTERPOLATION_PATTERN
raise ArgumentError.new('one hash required')
else
result = gsub(/%%?([{<])/, '%%\1')
result.send :'interpolate_without_ruby_19_syntax', args
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.