Permalink
Browse files

Merge branch 'master' into destructuring_blockargs

Conflicts:
	tests/block.fy
  • Loading branch information...
2 parents fc67c7c + f27c817 commit 8201322d3a4e8be6a5cc61c1ed8d4de32132bf8d @bakkdoor committed Sep 22, 2012
Showing with 46 additions and 0 deletions.
  1. +28 −0 lib/block.fy
  2. +18 −0 tests/block.fy
View
@@ -246,4 +246,32 @@ class Block {
iterations times: self
}
+
+ def then: block {
+ """
+ @block @Block@ to call after @self.
+ @return @Block@ that calls @self, then @block.
+
+ Example:
+ # prints \"Hello World!\"
+ { \"Hello\" print } then: { \"World!\" println }
+ """
+
+ { self call; block call }
+ }
+
+ alias_method: 'before: for: 'then:
+
+ def after: block {
+ """
+ @block @Block@ to call before @self.
+ @return @Block@ that calls @self after calling @block.
+
+ Example:
+ # prints \"Hello World!\"
+ { \"World!\" println } after: { \"Hello\" print }
+ """
+
+ { block call; self call }
+ }
}
View
@@ -323,6 +323,24 @@ FancySpec describe: Block with: {
'male, 'programmer, 'happy]
}
+ it: "returns a Block that calls self then a given Block" with: 'then: when: {
+ a = []
+ block = { a << 1 } then: { a << 2 }
+ block call
+ a is: [1,2]
+ block call
+ a is: [1,2,1,2]
+ }
+
+ it: "returns a Block that calls itself after a given Block" with: 'after: when: {
+ a = []
+ block = { a << 1 } after: { a << 2}
+ block call
+ a is: [2,1]
+ block call
+ a is: [2,1,2,1]
+ }
+
it: "allows argument destructuring / pattern matching" when: {
people = <[
"Tom Hanks" => (55, 'male, "New York"),

0 comments on commit 8201322

Please sign in to comment.