|e|?
-
Say we have the following line
edges.each { |e| e.erase! if e.valid? }what does the
ein|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}...
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better đź’—
Register LoginAdvertisement