Skip to content

Commit

Permalink
Added Block#=== to support using Blocks as match patterns. =)
Browse files Browse the repository at this point in the history
  • Loading branch information
bakkdoor committed Feb 3, 2011
1 parent a65383a commit 71262db
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/block.fy
Expand Up @@ -85,4 +85,8 @@ class Block {

unless: obj do: { self call }
}

def === val {
call: [val]
}
}
11 changes: 11 additions & 0 deletions tests/block.fy
Expand Up @@ -100,4 +100,15 @@ FancySpec describe: Block with: {
[1,2,3] map: @{to_s} . should == ["1", "2", "3"]
[1,2,3] map: @{to_s * 3} . should == ["111", "222", "333"]
}

it: "should execute a match clause if the block returns a true-ish value" for: '=== when: {
def do_match: val {
match val -> {
case |x| { x even? } -> "yup, it's even"
case _ -> "nope, not even"
}
}
do_match: 2 . should == "yup, it's even"
do_match: 1 . should == "nope, not even"
}
}

0 comments on commit 71262db

Please sign in to comment.