Injector Directives

9 views
Skip to first unread message

Lou Henry Alvarez

unread,
Oct 26, 2015, 3:18:06 PM10/26/15
to rubyonra...@googlegroups.com
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/.
Reply all
Reply to author
Forward
0 new messages