Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 41 lines (39 sloc) 1.805 kb
fc6e30f Updated to include a Ruby Cardinal. More to come!
Reg Braithwaite authored
1 # The MIT License
2 #
3 # All contents Copyright (c) 2004-2008 Reginald Braithwaite
7e71700 @raganwald updated links
raganwald authored
4 # <http://braythwayt.com> except as otherwise noted.
fc6e30f Updated to include a Ruby Cardinal. More to come!
Reg Braithwaite authored
5 #
6 # Permission is hereby granted, free of charge, to any person obtaining a copy
7 # of this software and associated documentation files (the "Software"), to deal
8 # in the Software without restriction, including without limitation the rights
9 # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 # copies of the Software, and to permit persons to whom the Software is
11 # furnished to do so, subject to the following conditions:
12 #
13 # The above copyright notice and this permission notice shall be included in
14 # all copies or substantial portions of the Software.
15 #
16 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 # THE SOFTWARE.
23 #
24 # http://www.opensource.org/licenses/mit-license.php
25
9346f30 parentheses for clarity
Reg Braithwaite authored
26 def cardinal_define(name, &proc_over_proc)
96388c9 slightly more idiomatic use of blocks
Reg Braithwaite authored
27 define_method_taking_block(name) do |a_value, a_proc|
28 proc_over_proc.call(a_proc).call(a_value)
29 end
fc6e30f Updated to include a Ruby Cardinal. More to come!
Reg Braithwaite authored
30 end
31
32 # method_body_proc should expect (a_value, a_proc)
33 # see http://coderrr.wordpress.com/2008/10/29/using-define_method-with-blocks-in-ruby-18/
96388c9 slightly more idiomatic use of blocks
Reg Braithwaite authored
34 def define_method_taking_block(name, &method_body_proc)
35 self.class.send :define_method, "__cardinal_helper_#{name}__", method_body_proc
fc6e30f Updated to include a Ruby Cardinal. More to come!
Reg Braithwaite authored
36 eval <<-EOM
37 def #{name}(a_value, &a_proc)
38 __cardinal_helper_#{name}__(a_value, a_proc)
39 end
40 EOM
41 end
Something went wrong with that request. Please try again.