Method: String#take

Defined in:
lib/ruby/jruby_hack.rb

#take(n) ⇒ String

Return the first n characters from the front

Examples:

"abc".take(0)   #=> ""
"abc".take(2)   #=> "ab"

Parameters:

  • n (Integer)

    number of characters to select (‘n > 0`)

Returns:

Raises:

  • (ArgumentError)


471
472
473
474
# File 'lib/ruby/jruby_hack.rb', line 471

def take(n)
  raise ArgumentError, "n must be positive" if n < 0
  self[0, n]
end