Sha256: e13f473c905ee9f08179ac1d52455ff15a5e57f109a7e6b8a601abff2c3e249a

Contents?: true

Size: 382 Bytes

Versions: 76

Compression:

Stored size: 382 Bytes

Contents

##
# @api public
#
# This monkeypatch extends Ruby 1.8 {String#%} with an ability
# to replace named capture groups, i.e.
# `"foo: %{bar}" % { :bar => 10 } # => "foo: 10"`.
#
class String
  alias original_percent %

  def %(arg, *args)
    if arg.is_a?(Hash)
      gsub(/%\{(\w+)\}/) do
        arg[$1.to_sym]
      end
    else
      original_percent(arg, *args)
    end
  end
end

Version data entries

76 entries across 76 versions & 5 rubygems

Version Path
dirwatch-0.0.9 vendor/bundle/ruby/2.5.0/gems/parser-2.4.0.2/lib/parser/compatibility/ruby1_8.rb
dirwatch-0.0.8 vendor/bundle/ruby/2.5.0/gems/parser-2.4.0.2/lib/parser/compatibility/ruby1_8.rb
dirwatch-0.0.6 vendor/bundle/ruby/2.3.0/gems/parser-2.4.0.2/lib/parser/compatibility/ruby1_8.rb
dirwatch-0.0.5 vendor/bundle/ruby/2.3.0/gems/parser-2.4.0.2/lib/parser/compatibility/ruby1_8.rb
dirwatch-0.0.4 vendor/bundle/ruby/2.3.0/gems/parser-2.4.0.2/lib/parser/compatibility/ruby1_8.rb
dirwatch-0.0.3 vendor/bundle/ruby/2.3.0/gems/parser-2.4.0.2/lib/parser/compatibility/ruby1_8.rb
dirwatch-0.0.2 vendor/bundle/ruby/2.3.0/gems/parser-2.4.0.0/lib/parser/compatibility/ruby1_8.rb
parser-2.4.0.2 lib/parser/compatibility/ruby1_8.rb
parser-2.4.0.1 lib/parser/compatibility/ruby1_8.rb
fluent-plugin-detect-memb-exceptions-0.0.2 vendor/bundle/ruby/2.0.0/gems/parser-2.4.0.0/lib/parser/compatibility/ruby1_8.rb
fluent-plugin-detect-memb-exceptions-0.0.1 vendor/bundle/ruby/2.0.0/gems/parser-2.4.0.0/lib/parser/compatibility/ruby1_8.rb
parser-2.4.0.0 lib/parser/compatibility/ruby1_8.rb
parser-2.3.3.1 lib/parser/compatibility/ruby1_8.rb
parser-2.3.3.0 lib/parser/compatibility/ruby1_8.rb
parser-2.3.2.0 lib/parser/compatibility/ruby1_8.rb
parser-2.3.1.4 lib/parser/compatibility/ruby1_8.rb
parser-2.3.1.3 lib/parser/compatibility/ruby1_8.rb
erruby_parser-2.3.1.2 lib/parser/compatibility/ruby1_8.rb
parser-2.3.1.2 lib/parser/compatibility/ruby1_8.rb
parser-2.3.1.1 lib/parser/compatibility/ruby1_8.rb