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:
Thanks for all your support,
lha