Created
June 23, 2009 15:26
-
-
Save madx/134591 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $:.unshift File.join(File.dirname(__FILE__), 'lib') | |
| require 'xup' | |
| module Animals | |
| module Cat | |
| def meow | |
| concat "meow!\n" | |
| end | |
| end | |
| module Dog | |
| def bark | |
| concat "woof!\n" | |
| end | |
| end | |
| end | |
| class DogContext < Xup::Context | |
| use Animals::Dog | |
| end | |
| context = Xup::Context.new do | |
| # On inclut Cat pour avoir accès à #meow | |
| use Animals::Cat | |
| meow | |
| build! do | |
| # Tous les modules inclus dans le contexte parent le sont ici aussi | |
| meow | |
| end | |
| build! :blank do | |
| # ici meow leve une erreur, Cat n'est pas hérité | |
| use Animals::Dog | |
| bark | |
| end | |
| build! :inherit, DogContext do | |
| # On hérite des modules du parent, et on spécifie un type particulier | |
| # de contexte | |
| meow | |
| bark | |
| end | |
| end | |
| puts context.buffer |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| meow! | |
| meow! | |
| woof! | |
| meow! | |
| woof! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment