array.each only returns the first value in Ruby -


I have the following command that gives a multiline string and I want to put it in an array and iterate it , Each line as a single element.

  DEP get_mnt_pts `grep VolGroup / proc / self / mounts | Awk '{Print $ 2, $ 4}' | Awk -F, '{print $ 1}' | Looks like before dividing raw input for DQ  
 > / rw / home rw / usr rw / tmp rw / var rw / var / Log rw   

I have the following code that looks like it takes the data and divides it by Newline and it is in an array. I then call the array to confirm And I can pull N values, but when I array. It only grabs the first value.

I think I have the entire string one element, but then. What did I have to think back to return? I have examined the ruby ​​doctor's array and also to see if I can understand it. I am doing a lot, I am making the array wrong, but it is not sure how.

  mount_info = Array.new mount_info = get_mnt_pts.split ("\ n") puts_info.length #thiss returns 6 mount_info .each do | Pt | / Pt>   

When I print mount_info myself, I get the following

  print mount_info ["/ rw" "/ Home rw "," / Usr rw "," / tmp rw "," / var rw "," / var / log rw "] is called mount_info / rw / home rw / usr rw / tmp rw / var rw / var / log rw Print mount_info [4] # Returns back / var RW mount_info [4] # layer back / var rw   

Not sure where to look from here, any direction is very good Will be. The end result is that for every element in the array, I want to try to write a file in that directory to confirm the file system, is actually worth writing. The array contains a list of mount points and for each mount point, I will write a tiemphil so that the block given below is taken in the array and repeat through it.

  def is_rw_test (mount_info) mount_info.each Do | Pt | Dir.exist? Pt.split [0] || @crit_pt_test & lt; & Lt; "# {Pt.split [0]}" file = temp.new ('.sensu', pt.split [0]) "We are writing to the temp file: # {file.path}" if config [: Debug] file.write ("mops") || @crit_pt_test & lt; & Lt; "# {Pt.split [0]}" file.read || @crit_pt_test & lt; & Lt; "# {Pt.split [0]}" file.close file.unlink return @crit_pt_test end end   

The code works fine, but only for the first element in the array, Although it does for everyone, I think my array has been assigned.

Thanks

def is_rw_test (mount_info) mount_info.each do | Pt | Dir.exist? Pt.split [0] || @crit_pt_test & lt; & Lt; "# {Pt.split [0]}" # Return @crit_pt_test # ohai End End

You have return , so it returns, and Not running through each .

If you want to assemble , do something about it:

  def is_rw_test (Mount_info) mount_info.collect do | Pt | Dir.exist? Pt.split [0] || @crit_pt_test & lt; & Lt; "# {Pt.split [0]}" # ATC @ crit_ pt_test end and   

but if so, then an example variable does not make any sense.

You have to decide what you really want do .

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#) -