I am learning Ruby from the Poignant Guide to Ruby and in some of the code examples, I came across uses of the double colon and dot that seem to be used for the same purpose:
File::open( 'idea-' + idea_name + '.txt', 'w' ) do |f|
f << idea
end
In the above code, the double colon is being used to access the open
method of the File
class. However, I later came across code that used a dot for the same purpose:
require 'wordlist'
# Print each idea out with the words fixed
Dir['idea-*.txt'].each do |file_name|
idea = File.read( file_name )
code_words.each do |real, code|
idea.gsub!( code, real )
end
puts idea
end
This time, a dot is being used to access the read
method of the File
class. What is the difference between:
File.read()
and
File::open()