Skip to content

Instantly share code, notes, and snippets.

@madx
Created June 23, 2009 15:26
Show Gist options
  • Select an option

  • Save madx/134591 to your computer and use it in GitHub Desktop.

Select an option

Save madx/134591 to your computer and use it in GitHub Desktop.
$:.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
meow!
meow!
woof!
meow!
woof!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment