Ruby on Rails Wednesday, September 9, 2015

This Jackbox feature showcases an alternative way to refine classes,
that also illustrates some additional uses of our modular
closures/injectors. For this to happen, we rely once again on our trusty
method #lets. Take a look at this example code:


# Injector declaration

StringExtensions = injector :StringExtensions do
def to_s
super + '++++'
end
end


# Jackbox Re-Classing

lets String do
include StringExtensions
end
str = String('boo')

assert(
str.to_s == 'boo++++'
)

assert(
String.new('bar).to_s == "bar"
)

For more details please visit:
http://blog.jackbox.us/2015/09/an-alternative-way-to-refine-class.html

--
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/25ad799f92de2600dfaeddfc01764ca6%40ruby-forum.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment