Sha256: 7cc0b76a6bb878714304904f332e758895578e9636ded746eec2a9af035a8231
Contents?: true
Size: 385 Bytes
Versions: 3
Compression:
Stored size: 385 Bytes
Contents
class String # Returns first _n_ characters. # # require 'facet/string/first_char' # # "Hello World".first_char(3) #=> "Hel" # def first_char(n=1) slice(0, n.to_i) end end # __TEST__ if __FILE__ == $0 require 'test/unit' class TestCase < Test::Unit::TestCase def test_first assert_equal( "Hel", "Hello World".first_char(3) ) end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
facets-0.7.0 | lib/facet/string/first_char.rb |
facets-0.7.1 | lib/facet/string/first_char.rb |
facets-0.7.2 | lib/facet/string/first_char.rb |