GitHub Sale: sign up for any paid plan this week and pay nothing until January 1, 2009!  [ hide ]

public
Rubygem
Description: Implements pattern-based method dispatch for Ruby, inspired by Topher Cyll's multi.
Clone URL: git://github.com/dyoder/functor.git
Updated docs and gemspec.
dyoder (author)
Sun Jun 15 18:16:12 -0700 2008
commit  d2f0932485a31b610edf8b580ffd59296bedc71c
tree    b9cee55353bc10b1a4cba3be20352ee7fc5e7e9a
parent  e147eeb2a89f384dc26921c6494fdda544debd18
...
14
15
16
17
18
 
 
19
20
21
...
46
47
48
49
50
51
52
53
 
 
 
 
54
55
56
57
58
 
59
60
61
...
14
15
16
 
 
17
18
19
20
21
...
46
47
48
 
 
 
 
 
49
50
51
52
53
54
55
56
 
57
58
59
60
0
@@ -14,8 +14,8 @@ spec = Gem::Specification.new do |s|
0
   s.required_ruby_version = '>= 1.8.6'
0
   s.name = "functor"
0
   s.rubyforge_project = 'functor'
0
- s.version = "0.3"
0
- s.authors = ["Dan Yoder"]
0
+ s.version = "0.3.1"
0
+ s.authors = [ "Dan Yoder", "Matthew King", "Lawrence Pit" ]
0
   s.email = 'dan@zeraweb.com'
0
   s.homepage = 'http://dev.zeraweb.com/'
0
   s.summary = "Pattern-based dispatch for Ruby, inspired by Topher Cyll's multi."
0
@@ -46,16 +46,15 @@ task :gemspec do
0
   end
0
 end
0
 
0
-#desc 'Publish rdoc to RubyForge.'
0
-#task :publish do
0
-# # `rsync -avz --delete doc/rdoc/ dyoder67@rubyforge.org:/var/www/gforge-projects/autocode/`
0
-# `scp -r doc/rdoc dyoder67@rubyforge.org:/var/www/gforge-projects/autocode/`
0
-#end
0
+desc 'Publish rdoc to RubyForge.'
0
+task :publish do
0
+ `rsync -a --delete doc/rdoc/ dyoder67@rubyforge.org:/var/www/gforge-projects/functor/`
0
+end
0
 
0
 Rake::RDocTask.new do |rdoc|
0
   rdoc.rdoc_dir = 'doc/rdoc'
0
   rdoc.options << '--line-numbers'
0
- rdoc.rdoc_files.add([ 'README', 'HISTORY', 'lib/*.rb' ])
0
+ rdoc.rdoc_files.add([ 'doc/README', 'doc/HISTORY', 'lib/*.rb' ])
0
 end
0
 
0
 Rake::TestTask.new(:test) do |t|
...
1
2
3
4
 
 
5
...
1
2
 
3
4
5
6
0
@@ -1,3 +1,4 @@
0
 0.1 - Initial implemention of Functor class.
0
 0.2 - Added method dispatch, to_proc support, tests.
0
-0.3 - Added support for guards and redefinition.
0
\ No newline at end of file
0
+0.3 - Added support for guards and redefinition.
0
+0.3.1 - Made thread-safe and added ability to call base class functors.
0
\ No newline at end of file
...
11
12
13
14
 
15
16
17
...
29
30
31
32
 
33
34
 
35
36
37
38
39
 
 
 
 
 
 
 
 
40
...
11
12
13
 
14
15
16
17
...
29
30
31
 
32
33
 
34
35
36
37
 
38
39
40
41
42
43
44
45
46
47
0
@@ -11,7 +11,7 @@ Functor provides pattern-based function and method dispatch for Ruby. To use it
0
   r.times = 5
0
   r.repeat( 5 ) # => 25
0
   r.repeat( "-" ) # => "- - - - -"
0
- r.repeat( 7.3 ) # => RuntimeError!
0
+ r.repeat( 7.3 ) # => ArgumentError!
0
 
0
 Warning: This defines a class instance variable @__functors behind the scenes as a side-effect. Also, although inheritance works within a functor method, super does not. To call the parent method, you need to call it explicitly using the #functors class method, like this:
0
 
0
@@ -29,10 +29,17 @@ You can use functors directly with functions taking a block like this:
0
 
0
   [ *0..10 ].map( &fib ) # => [0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55]
0
   
0
-You can explicitly bind self using #bind:
0
+You can call a functor as a method using #apply:
0
 
0
- fun.bind( obj )
0
+ fun.apply( obj, 7 )
0
   
0
 which is actually how the method dispatch is implemented.
0
 
0
-Arguments are matched first using === and then ==, so anything that supports these methods can be matched against.
0
\ No newline at end of file
0
+Arguments are matched first using === and then ==, so anything that supports these methods can be matched against. In addition, you may pass "guards," any object that responds to #call and which take and object (the argument) and return true or false. This allows you to do things like this:
0
+
0
+ stripe ||= Functor.new do
0
+ given( lambda { |x| x % 2 == 0 } ) { 'white' }
0
+ given( lambda { |x| x % 2 == 1 } ) { 'silver' }
0
+ end
0
+
0
+which will return "white" and "silver" alternately for a sequence of numbers.
0
\ No newline at end of file
...
1
2
3
 
4
5
6
7
8
9
 
 
10
11
 
12
13
14
...
1
2
 
3
4
5
6
7
 
 
8
9
10
 
11
12
13
14
0
@@ -1,14 +1,14 @@
0
 Gem::Specification.new do |s|
0
   s.name = %q{functor}
0
- s.version = "0.2"
0
+ s.version = "0.3.1"
0
 
0
   s.specification_version = 2 if s.respond_to? :specification_version=
0
 
0
   s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
0
- s.authors = ["Dan Yoder"]
0
- s.date = %q{2008-06-09}
0
+ s.authors = ["Dan Yoder", "Matthew King", "Lawrence Pit"]
0
+ s.date = %q{2008-06-15}
0
   s.email = %q{dan@zeraweb.com}
0
- s.files = ["doc/HISTORY", "doc/README", "lib/functor.rb", "lib/object.rb", "test/fib.rb", "test/functor.rb", "test/helpers.rb", "test/inheritance.rb"]
0
+ s.files = ["doc/HISTORY", "doc/README", "lib/functor.rb", "lib/object.rb", "test/fib.rb", "test/functor.rb", "test/guards.rb", "test/helpers.rb", "test/inheritance.rb", "test/matchers.rb", "test/reopening.rb"]
0
   s.has_rdoc = true
0
   s.homepage = %q{http://dev.zeraweb.com/}
0
   s.require_paths = ["lib"]

Comments

    No one has commented yet.