Continuing with our series: This time around we want to start a series
on Injector Directives.  We will begin by showing injector code
pre-withdrawal and then its subsequent re-instatement...

          facet :PreFunction do
            def pre
              puts '++++++++++'
            end
          end

          jack :PosFunction do
            def pos
              puts '=========='
            end
          end

          # Our class

          class Model

            inject PreFunction(:silence)
            inject PosFunction(:silence)

            def meth arg
              pre
              puts arg * arg
              pos
            end
          end
          obj = Model.new

          ############################
          # functionality is silent !!

          obj.meth( 2 )
          # ==> 4

          ############################
          # functionality is activated

          PreFunction(:active)
          PosFunction(:active)

          obj.meth( 2 )
          # ==> ++++++++++
          # ==> 4
          # ==> ==========

For more on this, please visit:
http://blog.jackbox.us/2015/10/injector-directives-collapse-and-rebuild.html


Thanks for all your support,

lha

-- 
Posted via http://www.ruby-forum.com/.

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-talk+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/57316295f4986ce56f963892eb49e18b%40ruby-forum.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to