Method: String#at

Defined in:
lib/ruby/jruby_hack.rb

#at(n) ⇒ String

Return the one-character string at the given index

Examples:

"abc".at(0)   #=> "a"
"abc".at(2)   #=> "c"

Parameters:

  • n (Integer)

    zero-based index of the character to read

Returns:

Raises:

  • (ArgumentError)


443
444
445
446
# File 'lib/ruby/jruby_hack.rb', line 443

def at(n)
  raise ArgumentError, "n must be positive" if n < 0
  self[n, 1] unless n >= length
end