Module: Pacer::Transform::Map
- Defined in:
- lib/pacer/transform/map.rb
Instance Attribute Summary collapse
-
#block ⇒ Object
Returns the value of attribute block.
Instance Method Summary collapse
Instance Attribute Details
#block ⇒ Object
Returns the value of attribute block.
12 13 14 |
# File 'lib/pacer/transform/map.rb', line 12 def block @block end |
Instance Method Details
#help(section = nil) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/pacer/transform/map.rb', line 14 def help(section = nil) case section when nil puts "Works much like Ruby's built-in map method but has some extra options and,\nlike all routes, does not evaluate immediately (see the :routes help topic).\n\nExample:\n\n mapped = [1,2,3].to_route.map { |n| n + 1 } #=> #<Obj -> Obj-Map>\n\n mapped.to_a #=> [2,3,4]\n mapped.limit(1).to_a #=> [2]\n\nNote that the block will be called *twice* in the above example where limit(1)\nis applied to the route after the map is defined. Routes do some pre-processing\nand you can not assume that a function executed within a route will be executed\nthe expected number of times without carefully testing your logic.\n\nFurther, note that routes may be re-executed multiple times:\n\n [mapped.to_a, mapped.to_a] #=> [[2,3,4], [2,3,4]]\n\nThe element_type option is frequently useful. The following looks up elements\nby ID in the graph and produces a fully-fledged vertices route:\n\n route = [1,2,3].to_route\n mapped = route.map(graph: g, element_type: :vertex) { |n| g.vertex(n) }\n\n mapped.out_e #=> #<Obj -> V-Map -> outE>\n mapped.in_e #=> #<Obj -> V-Map -> inE>\n\nIf you want to map over a route immediately without adding a map step to it,\nuse the synonym for #map built-in to Ruby: #collect\n\n [1,2,3].to_route.collect { |n| n + 1 } #=> [2,3,4]\n\n" else super end description end |