Created
May 1, 2014 23:25
-
-
Save shinokada/11464301 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def readfile1(file_name) | |
# read a file and returns string "17 10 16 3 7 " | |
file = File.open(file_name) | |
contents = file.read.gsub(/\r\n/, ' ') | |
end | |
def readfile2(file_nam) | |
# same as above | |
File.readlines(file_name).map(&:chomp).join(' ') | |
end | |
def readfile3(file_name) | |
File.readlines(file_name).map(&:chomp) # ["17", "10", "16", "3", "7"] | |
.join(' ') # "17 10 16 3 7" | |
end | |
# by using the above method by spliting gives each value | |
def reafile3a(file_name) | |
# read a file and map(&:chomp) will give a string | |
# and gives 4 items, hol, jap, math max_jap values etc. | |
hol, jap, math, max_jap, max_math= File.readlines(file_name).map(&:chomp).join(' ').split(' ') | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment