windows - Weird File.open behavior when using different closure types in Ruby -


I started learning chefs to manage my servers and in a very strange (my opinion) behavior in Ruby Stumbled I do not know Ruby, so this can only be a misunderstanding from my part.

I was getting

  'delete': permission denied - [some path] / metadata.Jason (Errno :: EACCES)   

Because I knew that it was not really about permissions, the next logical point was that file locking should be checked after a little dig through the relevant code, I came to know that there is a method that Produces a checksum for each file.

  •   def checksum_file (file, digest) File.open (file, 'rb') {| F | | Checksum_io (f, digest)} end def checksum_io (IO, digest) while chunk = io.read (1024 × 8) digest. Adate (Chuck) end digest. After being Hexdigest end   

    that I searched for a little and found out about closing the files in Ruby and it appears that the code was actually ok ... but this is not Was there. I tried to convert the method to "Block format" and it worked without error:

      def checksum_file (file, digest) file. Open, 'rb'). F |   

    Can anyone please understand the difference in the two versions of the code?

    - Edit -

    It seems that this problem is only in Windows and probably only when the rabbi provided by Shefda 0.3.0 Is used:

    Ruby 2.0.0p451 (2014-02-24) [i386-mingw32]

    Answer to your question

    Can someone please explain the difference between the two versions of the code?

    • The block always returns something like do end and and {...} No matter what it really is, it's just a programming preference.

    • I now want to share with you two separate conferences and it depends on you which religion you want to subscribe to.

      The first religion says that

      when you have a single line or single e-line block you will use curly braces and if you have multi line block you will use do and end . words.each {| Word | Words) # Single row or single row block word Words | Words | # The word P1 end in multi-line block

      The second religion says that

      if your block has only some side effects and Keep in mind about the non-refundable value you can do and terminate

        words.each do | Words | The end of the word   

      where you take care of the return value, you {...}

        back_words = words.map {| Word | Word.reverse}   

      Hope I answer your question !!!

  • Comments

    Popular posts from this blog

    java - ImportError: No module named py4j.java_gateway -

    python - Receiving "KeyError" after decoding json result from url -

    .net - Creating a new Queue Manager and Queue in Websphere MQ (using C#) -