Skip to content

Commit

Permalink
add Block#then: & Block#after:
Browse files Browse the repository at this point in the history
  • Loading branch information
bakkdoor committed Sep 22, 2012
1 parent a622546 commit f27c817
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
28 changes: 28 additions & 0 deletions lib/block.fy
Expand Up @@ -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 }
}
}
18 changes: 18 additions & 0 deletions tests/block.fy
Expand Up @@ -322,4 +322,22 @@ FancySpec describe: Block with: {
['city, "San Francisco"],
'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]
}
}

0 comments on commit f27c817

Please sign in to comment.