sketchucation logo sketchucation
    • Login
    🤑 SketchPlus 1.3 | 44 Tools for $15 until June 20th Buy Now

    |e|?

    Scheduled Pinned Locked Moved Developers' Forum
    3 Posts 2 Posters 211 Views 2 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • R Offline
      remus
      last edited by

      Say we have the following line edges.each { |e| e.erase! if e.valid? }

      what does the e in |e| stand for?

      http://remusrendering.wordpress.com/

      1 Reply Last reply Reply Quote 0
      • R Offline
        remus
        last edited by

        Cool, that makes sense. Thanks.

        http://remusrendering.wordpress.com/

        1 Reply Last reply Reply Quote 0
        • TIGT Offline
          TIG Moderator
          last edited by

          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}
          

          ...

          TIG

          1 Reply Last reply Reply Quote 0
          • 1 / 1
          • First post
            Last post
          Buy SketchPlus
          Buy SUbD
          Buy WrapR
          Buy eBook
          Buy Modelur
          Buy Vertex Tools
          Buy SketchCuisine
          Buy FormFonts

          Advertisement