ruby - Overwriting #each; can I pass it args through #map, #select, etc? -
I have written my own Here's the problem when I wrote for This is a short version of my code; I want to call things like this; I'm pretty stupid. The method Apply the syntax of Charlie in each of my traversal ways that calculates the width according to the algorithm first; Any tree class which contains
anonymous
tree then returns a
# iH function. As a result, it automatically receives
numeric functions like
#map ,
#select ,
#find
#each my
tree , I gave a code which is
# iH Is an argument used by the name of the tree traversell algorithm, such as
: pre_order or
: breadth_first . But now when I
#map or
#inject or
#any? et, it can only use the default traversal algorithm, is there any way that I can pass this argument through another
innovative function? Here are my criteria;
numerical function. It is very important because different algorithms for trees are very different Can be demonstrated.
numerical function to pass this argument to
#each ; Which defeats the purpose of the module.
are included in the class tree ... # overwrite #hash, and make it algorithmic argument. DRF Each (Algorithm =: Pre_Order, and Block) if TravelWill_Algorithms are included in this? Algorithms self.send (algorithm, and block) other self.method_missing (algorithm) end-end pre-order (& amp; block) sub-self.branches.each Branch; Branch.pre_order (& amp; block) end-end def post_order (& block) ... end def fourth_ & nbsp; (& Amp; Block) ... and end
tree.find (13, breadth_first) tree.any? (: Post_order) do | Node | node.root & gt; = 10 end
#enum_for gives me all the power here by adding the traditional line
tree.breadth_first.find (13)
Change to self.enum_for (__ method__) until block_life is not there?
tree.breadth_first will return a
calculator
enforced method will be used internally for that calculation.
Comments
Post a Comment