summaryrefslogtreecommitdiffstats
path: root/examples/hello_world.rb
diff options
context:
space:
mode:
authorJérémy Zurcher <jeremy@asynk.ch>2012-06-10 23:35:01 +0200
committerJérémy Zurcher <jeremy@asynk.ch>2012-06-10 23:35:01 +0200
commitb643db44cb4cf91b7b5d2a2dd4a46c29eee9ccfb (patch)
tree2f6897345a1365eb3e66bf09a6483e71f98b1404 /examples/hello_world.rb
parentb3c15d2d42c9be803cd55d52b0566041c8a1420e (diff)
downloadedoors-ruby-b643db44cb4cf91b7b5d2a2dd4a46c29eee9ccfb.zip
edoors-ruby-b643db44cb4cf91b7b5d2a2dd4a46c29eee9ccfb.tar.gz
add examples
Diffstat (limited to 'examples/hello_world.rb')
-rw-r--r--examples/hello_world.rb50
1 files changed, 50 insertions, 0 deletions
diff --git a/examples/hello_world.rb b/examples/hello_world.rb
new file mode 100644
index 0000000..69befd4
--- /dev/null
+++ b/examples/hello_world.rb
@@ -0,0 +1,50 @@
+#! /usr/bin/env ruby
+# -*- coding: UTF-8 -*-
+#
+# run from project top directory with : ruby -Ilib examples/hello_world.rb
+#
+require 'edoors'
+#
+class InputDoor < Edoors::Door
+ #
+ def start!
+ # stimulate myself
+ send_p require_p(Edoors::Particle), Edoors::ACT_GET
+ end
+ #
+ def receive_p p
+ if p.action==Edoors::ACT_GET
+ p.reset!
+ p.set_data 'txt', "hello world"
+ send_p p # will follow the default link
+ else
+ puts p.action
+ # we can release it or let the Door do it
+ release_p p
+ end
+ end
+ #
+end
+#
+class OutputDoor < Edoors::Door
+ #
+ def receive_p p
+ puts p.get_data('txt')
+ # let the door release it
+ end
+ #
+end
+#
+if $0 == __FILE__
+ #
+ dom0 = Edoors::Spin.new 'dom0'
+ input = InputDoor.new 'input', dom0
+ output = OutputDoor.new 'output', dom0
+ dom0.add_link Edoors::Link.new('input', 'output', nil, nil, nil)
+ #
+ dom0.spin!
+ dom0.hibernate!
+ #
+end
+#
+# EOF