You can choose to read an arbitrary number of bytes from a file into a single variable using read:
File.open("main.rb") do |f| puts f.read(6) end
You can use all these methods on any file, such as binary files.