Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #--
- # George Moschovitis <gm@navel.gr>
- #++
- class Module
- # A useful macro for dynamic modules.
- #--
- # FIXME: quick and easy implementation, should
- # come up with something better. The name
- # sucks too.
- #++
- def on_included(code)
- tag = caller[0].split(' ').first.split(/\/|\\/).last.gsub(/:|\.|\(|\)/, '_')
- old = "__included_#{tag}"
- module_eval %{
- class << self
- alias_method :#{old}, :included
- def included(base)
- #{old}(base)
- #{code}
- end
- end
- }
- end
- end
- =begin Testing
- module M
- on_included %{
- puts 'hello'
- }
- end
- module Q
- on_included %{
- puts 'world'
- }
- on_included %{
- puts 'it works'
- }
- end
- class C
- include M
- include Q
- end
- =end
Add Comment
Please, Sign In to add comment