Injector Directives

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

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs