Ruby on Rails Thursday, November 19, 2015

This flavor of the inheritance model allows our modular closures to have
similar properties to the inheritance of classes. With it you can
expect to have access to its super members as part of the call, just
like you would with classes. In addition to the inheritance resulting
from versioning, JIT inheritance presents a more complete scenario
adding color to the picture painted by code injectors. The key takeaway
here is this: Code Injectors are mix-ins that share a similar
inheritance model with classes. You can version them to gain access to
versioned inheritance or you can override its members to access an
ancestor chain comprised of all previous tags. As always we will use
some example code to illustrate:

#
# Our Modular Closure
#
Tag1 = jack :Tagger do
def m1
1
end

def m2
:m2
end
end

#
# Normal Versioned Injector inheritance
#
Tagger do
def other
'other' # -- same ancestors as before
end
end

expect(Tagger().ancestors).to eql( [Tagger()] )

# test it

o = Object.new.extend(Tagger())

# inherited
o.m1.should == 1
o.m2.should == :m2

# current
o.other.should == 'other'


#
# JIT inheritance
#
Tag2 = Tagger do
def m1 # The :m1 override invokes JIT inheritance
super + 1 # -- Tag1 is summoned into ancestor chain
end # -- allows the use of super

def m3
'em3'
end
end

# test it

p = Object.new.extend(Tag2)

# JIT inherited
p.m1.should == 2

# regular inheritance
p.m2.should == :m2
p.m3.should == 'em3'
p.other.should == 'other'

expect(Tagger().ancestors).to eql( [Tagger(), Tag1] )
expect(Tag2.ancestors).to eql( [Tag2, Tag1] )


For more please visit: http://jackbox.us

Thanks again,

Lou

--
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+unsubscribe@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/2664125f58d1bae5d1ae1e54860b7d1e%40ruby-forum.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment