|e|?
-
Say we have the following line
edges.each { |e| e.erase! if e.valid? }
what does the
e
in|e|
stand for? -
Cool, that makes sense. Thanks.
-
In your example e = edge... there are several ways of doing everything in Ruby...
edges.each{|e|e.erase! if e.valid?} # is the same as... edges.each{|edge|edge.erase! if edge.valid?} # is the same as... edges.each{|edge| if edge.valid? edge.erase! end#if }
So 'each' of the 'edges' - called 'edge' (or whatever) is processed in turn inside the {}: 'edge' as a variable doesn't survive outside of the {} unless you declare it outside of them later...
It's become something of a standard to use |e| as 'entity'... However, whatever text is inside the the || it is used as the variable you are interested in. It CAN be anything 'legal'...Sketchup.active_model.entities.each{|e|puts e.typename; puts "the next entity..."}
here 'e' is the same as 'entity'
Sketchup.active_model.entities.each{|entity|puts entity.typename; puts "the next entity..."}
I comes down to choice and clarity - if you use it briefly the 'e' might be fine, if 'e' is drifting about many lines of code later, then you might have prefer it to have been called 'edge' or something clearer...
mats=[];Sketchup.active_model.materials.each{|material|mats.push(material.name)} mats.each{|e|puts e}
...
Advertisement