ruby - Difference between Dir[File.join(File.dirname(__FILE__), '..', 'lib', '**/*.rb')].each { |f| require f } and $ << File.join(File -
Is there any difference between these two codes for spec_helper.rb?
Or things to do this practically?
$ < & Lt; File. (File. Dainam (file), '..', 'Lib') Dir [File.join (File.dirname (__ FILE__), '..', 'lib', '** / * .rb')] . Each {| F | |
They are not exactly the same.
file.join (File.dirname (FILE), '..', 'lib') does not work right version of file. (File. Dynamic (__ Fail__), '..', 'lib') depends on which takes the path of the file that is in that line and he joins / (with your OS course) With '..' and 'lib' . So in the end you get a string (nothing) that '/ location-of-the-file /../lib' As the File.dirname (__ FILE__), '..', 'lib', '** / * Dir.glob (see based on the input string .rb')) (which again is what I do Describe above). Dir [String] Result array of all files (only one string and nothing) that match the globing string. In this case, all the files in LibreOffice Directory (including sub-dealers) that expire in .rb Then the code goes to each string that represents a file and has a requirement (loading the code in the current file).
Comments
Post a Comment