Created
January 11, 2013 17:00
-
-
Save rebo/4512300 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
| # | |
| # Simple Context Example: | |
| # | |
| $LOAD_PATH.unshift File.expand_path(File.join(File.dirname(__FILE__), "..", "lib")) | |
| require 'hybrid_dci' | |
| Foo = Struct.new(:name) do | |
| include HybridDCI::Data | |
| end | |
| class SimpleContext | |
| include HybridDCI::Context | |
| role :greeter do | |
| contract :name | |
| def say_hi | |
| puts "Hello there! says #{name}" | |
| end | |
| end | |
| role :goodbye_guy do | |
| contract :name | |
| def say_bye | |
| puts "Goodbye! says #{name}" | |
| end | |
| end | |
| def initialize | |
| @a_foo = Foo.new("Arthur") | |
| bind_roles(:greeter => @a_foo, :goodbye_guy=> @a_foo) | |
| end | |
| def execute | |
| in_context do | |
| greeter(:call).say_hi | |
| goodbye_guy(:call).say_bye | |
| end | |
| end | |
| end | |
| context = SimpleContext.new | |
| context.execute | |
| # => | |
| # >> Hello there! says Arthur | |
| # >> Goodbye! says Arthur |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment