Is there any similar peek(); (From C++) function in ruby? Any alternative to do this?
I've found a way to do this.
Use the StringScanner:
require 'strscan'
scanner = StringScanner.new(YourStringHere)
puts scanner.peek(1)
You can use the StringScanner to scan files as well:
file = File.open('hello.txt', 'rb')
scanner = StringScanner.new(file.read)