Sha256: 5ca10baca1dbab7c64fb4ba5d01bd983309d3da11cabc70b256aa20b8b8c10e5
Contents?: true
Size: 1.04 KB
Versions: 10
Compression:
Stored size: 1.04 KB
Contents
# TITLE: # # String Interpolation # # SUMMARY: # # Provides a method of extenally using # Ruby string interpolation mechinism. # # This library also providea a couple # aliases for % as sprintf and format. # # CREDIT: # # - Thomas Sawyer # # TODO: # # - The String::format and String::sprintf methods # really not very useful and will likely be # deprecated eventually, since they are already # included in Kernel. # class String # Interpolate. def self.interpolate(&str) eval "%{#{str.call}}", str.binding end # def self.format(*args) Kernel.format(*args) end def self.sprintf(*args) Kernel.format(*args) end # alias_method :format, :% alias_method :sprintf, :% end # _____ _ # |_ _|__ ___| |_ # | |/ _ \/ __| __| # | | __/\__ \ |_ # |_|\___||___/\__| # =begin test require 'test/unit' class TestStringInterpolate < Test::Unit::TestCase def test_interpolate a = 1 assert_equal('this is 1', String.interpolate{ 'this is #{a}' }) end end =end
Version data entries
10 entries across 10 versions & 1 rubygems