Permalink
Browse files

fix Symbol#arity to return the correct value

  • Loading branch information...
1 parent 029b3a4 commit b874239c1b769e22534386a383ff0d5bc3980b1b @bakkdoor committed Oct 1, 2012
Showing with 15 additions and 1 deletion.
  1. +6 −1 lib/symbol.fy
  2. +9 −0 tests/symbol.fy
View
@@ -54,7 +54,12 @@ class Symbol {
}
def arity {
- 1
+ m = message_name to_s
+ match m {
+ case /^:[a-zA-Z0-9_]+$/ -> m count: @{ == ":" }
+ case /^:\W+$/ -> 2
+ case _ -> m count: @{ == ":" } + 1
+ }
}
def to_sym {
View
@@ -28,6 +28,15 @@ FancySpec describe: Symbol with: {
if: x then: 'foo else: 'bar . is: "foo"
}
+ it: "returns its arity correctly (when interpreted as a method name)" with: 'arity when: {
+ 'foo arity is: 1
+ 'foo_bar_baz arity is: 1
+ ('+, '-, '*, '/) each: @{ arity is: 2 }
+ 'foo: arity is: 2
+ 'foo:bar: arity is: 3
+ 'foo:bar:baz: arity is: 4
+ }
+
it: "returns self" with: 'to_sym when: {
'foo to_sym is: 'foo
'bar to_sym is: 'bar

0 comments on commit b874239

Please sign in to comment.