title: Trouble with combined logic in ruby
body: <p>writing a simple monte carlo simulation of a neutron beam. Having trouble with the geometry logic (whether something is in one environment or another). My issue is that Ruby seems to be processing the conditions sequentially and keeping the first value it comes to.</p>
  
  <p>The code below illustrates this quite nicely:</p>
  
  <pre><code>def checkPosition(*args)
  
    polyCylRad = 2.5
    polyCylFr = 15
    polyCylB = -2.0
    borPolyBoxL = 9.0 / 2
    pbCylRad = 3.0
    pbBoxL = 10.0 / 2
    cdBoxL = 9.5 / 2
  
    position = Array.new
    material = String.new
  
    args.each do |item|
      position &lt;&lt; item.inspect.to_f
    end
    xSquared = position.at(0) ** 2
    ySquared = position.at(1) ** 2
    zSquared = position.at(2) ** 2
    modX = Math.sqrt(xSquared)
    modY = Math.sqrt(ySquared)
    modZ = Math.sqrt(zSquared)
  
    puts xSquared
    puts Math.sqrt(ySquared + zSquared) &lt;= polyCylRad
    puts (position.at(0) &gt;= polyCylB)
    puts (position.at(0) &lt;= polyCylFr)
    puts (position.at(0) &gt;= polyCylB)and(position.at(0) &lt;= polyCylFr)
    puts (position.at(0) &lt;= polyCylFr)and(position.at(0) &gt;= polyCylB)
  
    puts zSquared
  
  
    polyCylinder = (Math.sqrt(ySquared + zSquared) &lt;= polyCylRad)and((position.at(0) &gt;= polyCylB)and(position.at(0) &lt;= polyCylFr) )
    puts polyCylinder
    borPolyBox = ((modX &lt;= borPolyBoxL)or(modY &lt; borPolyBoxL)or(modZ &lt;= borPolyBoxL)) and not((modX &gt;= cdBoxL)or(modY &gt;= cdBoxL)or(modZ &gt;= cdBoxL)) and not(Math.sqrt(ySquared + zSquared) &lt;= polyCylRad)
    puts borPolyBox
    cadmiumShield = ((modX &lt;= cdBoxL)or(modY &lt; cdBoxL)or(modZ &lt;= cdBoxL)) and not((modX &gt;= pbBoxL)or(modY &gt;= pbBoxL)or(modZ &gt;= pbBoxL)) and not(Math.sqrt(ySquared + zSquared) &lt;= polyCylRad)
    puts cadmiumShield
    leadShield = ( ((modX &lt;= pbBoxL)or(modY &lt;= pbBoxL)or(modZ &lt;= pbBoxL)) or ((position.at(0) &lt;= ployCylFr)and(Math.sqrt(ySquared + zSquared) &lt;= pbCylRad)) ) and not(Math.sqrt(ySquared + zSquared) &lt;= polyCylRad)
    puts leadShield
  
    if (polyCylinder) : material = "poly"
    elsif(borPolyBox) : material = "borPoly"
    elsif(cadmiumSheild) : material = "cd"
    elsif(leadSheild) : material = "pb"
    elsif(material == nil) : position = Array.new
    end
  
    thisEnvironment = Array.new
    thisEnvironment &lt;&lt; position &lt;&lt; material
    puts thisEnvironment.at(0)
    puts thisEnvironment.at(1)
  end
  
  checkPosition(40, 0, 0)
  </code></pre>
  
  <p>call the code whatever you want, but give it *args as an argument (I am lazy and may want to add more args in the future) then call it with 3 floats, wrt the geometry set up in the logic and you'll see what I mean.</p>
  
  <p>My question is: how do I get it to work like it should (ie evaluating the logic correctly) without a whole bunch of nested if's? (which is what I am about to remake, however it is a nightmare to read and memory is cheap.)</p>