Sha256: d74a97432d3016f1ee905b5b76b495f23dc6c8ba0e4cb90c52036613655400d7
Contents?: true
Size: 1.18 KB
Versions: 1
Compression:
Stored size: 1.18 KB
Contents
require 'nano/string/bracket' class String # Return a new string embraced by given quotes. # If no quotes are specified, then assumes single quotes. # # "quote me".quote #=> "'quote me'" # "quote me".quote(2) #=> "\"quote me\"" # def quote(type=:s) case type.to_s.downcase when 's', 'single' bracket("'") when 'd', 'double' bracket('"') when 'b', 'back' bracket('`') else bracket("'") end end end # _____ _ # |_ _|__ ___| |_ # | |/ _ \/ __| __| # | | __/\__ \ |_ # |_|\___||___/\__| # =begin test require 'test/unit' class TCString < Test::Unit::TestCase def setup @a = "hi" end def test_001 assert_raises( ArgumentError ) { @a.quote(1,2) } end def test_002 assert_equal( %{'hi'}, @a.quote ) end def test_003 assert_equal( %{"hi"}, @a.quote(:d) ) assert_equal( %{"hi"}, @a.quote(:double) ) end def test_004 assert_equal( %{'hi'}, @a.quote(:s) ) assert_equal( %{'hi'}, @a.quote(:single) ) end def test_005 assert_equal( %{`hi`}, @a.quote(:b) ) assert_equal( %{`hi`}, @a.quote(:back) ) end end =end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
facets-0.9.0 | lib/nano/string/quote.rb |