defmacro 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,6 @@
1
+ === 0.0.1 / 2008-06-09
2
+
3
+ * 1 major enhancement
4
+
5
+ * Birthday!
6
+
@@ -0,0 +1,7 @@
1
+ History.txt
2
+ Manifest.txt
3
+ README.rdoc
4
+ README.txt
5
+ Rakefile
6
+ lib/def_macro.rb
7
+ test/test_def_macro.rb
@@ -0,0 +1,69 @@
1
+ = def_macro
2
+
3
+ * http://github.com/dfg59/def_macro/tree/master
4
+
5
+ == DESCRIPTION:
6
+
7
+ Macros for ruby
8
+
9
+ == FEATURES/PROBLEMS:
10
+
11
+ * A few features, probably lots of problems
12
+
13
+ == SYNOPSIS:
14
+
15
+ The classic with macro:
16
+
17
+ def_macro :with do |args,body|
18
+ eval args.first
19
+ eval body
20
+ end
21
+
22
+ with proc { a = 1; b = 2 } do
23
+ puts a + b
24
+ end # => 3
25
+
26
+ The classic loop macro:
27
+
28
+ def_macro :loop do |args,body|
29
+ (eval args.first).times do
30
+ eval body
31
+ end
32
+ end
33
+
34
+ loop 2 do
35
+ puts "hi"
36
+ end # => "hi" "hi"
37
+
38
+ == REQUIREMENTS:
39
+
40
+ * ruby2ruby 1.1.9 or later
41
+
42
+ == INSTALL:
43
+
44
+ * sudo gem install dfg59-def_macro --source=http://gems.github.com
45
+
46
+ == LICENSE:
47
+
48
+ (The MIT License)
49
+
50
+ Copyright (c) 2008 Drew Olson
51
+
52
+ Permission is hereby granted, free of charge, to any person obtaining
53
+ a copy of this software and associated documentation files (the
54
+ 'Software'), to deal in the Software without restriction, including
55
+ without limitation the rights to use, copy, modify, merge, publish,
56
+ distribute, sublicense, and/or sell copies of the Software, and to
57
+ permit persons to whom the Software is furnished to do so, subject to
58
+ the following conditions:
59
+
60
+ The above copyright notice and this permission notice shall be
61
+ included in all copies or substantial portions of the Software.
62
+
63
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
64
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
65
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
66
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
67
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
68
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
69
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,69 @@
1
+ = def_macro
2
+
3
+ * http://github.com/dfg59/def_macro/tree/master
4
+
5
+ == DESCRIPTION:
6
+
7
+ Macros for ruby
8
+
9
+ == FEATURES/PROBLEMS:
10
+
11
+ * A few features, probably lots of problems
12
+
13
+ == SYNOPSIS:
14
+
15
+ The classic with macro:
16
+
17
+ def_macro :with do |args,body|
18
+ eval args.first
19
+ eval body
20
+ end
21
+
22
+ with proc { a = 1; b = 2 } do
23
+ puts a + b
24
+ end # => 3
25
+
26
+ The classic loop macro:
27
+
28
+ def_macro :loop do |args,body|
29
+ (eval args.first).times do
30
+ eval body
31
+ end
32
+ end
33
+
34
+ loop 2 do
35
+ puts "hi"
36
+ end # => "hi" "hi"
37
+
38
+ == REQUIREMENTS:
39
+
40
+ * ruby2ruby 1.1.9 or later
41
+
42
+ == INSTALL:
43
+
44
+ * sudo gem install dfg59-def_macro --source=http://gems.github.com
45
+
46
+ == LICENSE:
47
+
48
+ (The MIT License)
49
+
50
+ Copyright (c) 2008 Drew Olson
51
+
52
+ Permission is hereby granted, free of charge, to any person obtaining
53
+ a copy of this software and associated documentation files (the
54
+ 'Software'), to deal in the Software without restriction, including
55
+ without limitation the rights to use, copy, modify, merge, publish,
56
+ distribute, sublicense, and/or sell copies of the Software, and to
57
+ permit persons to whom the Software is furnished to do so, subject to
58
+ the following conditions:
59
+
60
+ The above copyright notice and this permission notice shall be
61
+ included in all copies or substantial portions of the Software.
62
+
63
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
64
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
65
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
66
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
67
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
68
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
69
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,15 @@
1
+ # -*- ruby -*-
2
+
3
+ require 'rubygems'
4
+ require 'hoe'
5
+ require './lib/def_macro.rb'
6
+
7
+ Hoe.new('defmacro', DefMacro::VERSION) do |p|
8
+ p.rubyforge_name = 'defmacro'
9
+ p.developer('Drew Olson', 'drew@drewolson.org')
10
+ p.extra_deps << ['ruby2ruby', '>= 1.1.9']
11
+ p.extra_deps << ['need', '>= 1.1.0']
12
+ p.remote_rdoc_dir = ''
13
+ end
14
+
15
+ # vim: syntax=Ruby
@@ -0,0 +1,37 @@
1
+ require 'rubygems'
2
+ require 'ruby2ruby'
3
+
4
+ module DefMacro
5
+ VERSION = "0.0.1"
6
+
7
+ def self.cleanse_body(body)
8
+ body = body.split("\n")
9
+ if body.size > 1
10
+ body[1...-1].join("\n")
11
+ else
12
+ cleanse_arg(body.first)
13
+ end
14
+ end
15
+
16
+ def self.cleanse_arg(arg)
17
+ arg[/\{([^}]+)\}/,1]
18
+ end
19
+ end
20
+
21
+ class Object
22
+ def def_macro(name,&body)
23
+ class_eval <<-EOS
24
+ def #{name}(*args,&block)
25
+ mac_body = DefMacro.cleanse_body(block.to_ruby)
26
+ args.map! do |arg|
27
+ if arg.kind_of? Proc
28
+ DefMacro.cleanse_arg(arg.to_ruby)
29
+ else
30
+ arg.to_s
31
+ end
32
+ end
33
+ (eval "#{body.to_ruby}").call(args,mac_body)
34
+ end
35
+ EOS
36
+ end
37
+ end
@@ -0,0 +1,23 @@
1
+ require "test/unit"
2
+ require 'rubygems'
3
+ require 'need'
4
+ need { "../lib/def_macro" }
5
+
6
+ class Foo
7
+ def_macro :with do |args,body|
8
+ eval args.first
9
+ eval body
10
+ end
11
+ end
12
+
13
+ class TestDefMacro < Test::Unit::TestCase
14
+ def test_with_macro
15
+ foo = Foo.new
16
+
17
+ result = foo.with proc { a = 1; b = 3 } do
18
+ a + b
19
+ end
20
+
21
+ assert_equal(4, result)
22
+ end
23
+ end
metadata ADDED
@@ -0,0 +1,89 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: defmacro
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Drew Olson
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-06-11 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: ruby2ruby
17
+ version_requirement:
18
+ version_requirements: !ruby/object:Gem::Requirement
19
+ requirements:
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 1.1.9
23
+ version:
24
+ - !ruby/object:Gem::Dependency
25
+ name: need
26
+ version_requirement:
27
+ version_requirements: !ruby/object:Gem::Requirement
28
+ requirements:
29
+ - - ">="
30
+ - !ruby/object:Gem::Version
31
+ version: 1.1.0
32
+ version:
33
+ - !ruby/object:Gem::Dependency
34
+ name: hoe
35
+ version_requirement:
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: 1.5.3
41
+ version:
42
+ description: Macros for ruby
43
+ email:
44
+ - drew@drewolson.org
45
+ executables: []
46
+
47
+ extensions: []
48
+
49
+ extra_rdoc_files:
50
+ - History.txt
51
+ - Manifest.txt
52
+ - README.txt
53
+ files:
54
+ - History.txt
55
+ - Manifest.txt
56
+ - README.rdoc
57
+ - README.txt
58
+ - Rakefile
59
+ - lib/def_macro.rb
60
+ - test/test_def_macro.rb
61
+ has_rdoc: true
62
+ homepage: http://github.com/dfg59/def_macro/tree/master
63
+ post_install_message:
64
+ rdoc_options:
65
+ - --main
66
+ - README.txt
67
+ require_paths:
68
+ - lib
69
+ required_ruby_version: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ version: "0"
74
+ version:
75
+ required_rubygems_version: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ version: "0"
80
+ version:
81
+ requirements: []
82
+
83
+ rubyforge_project: defmacro
84
+ rubygems_version: 1.1.1
85
+ signing_key:
86
+ specification_version: 2
87
+ summary: Macros for ruby
88
+ test_files:
89
+ - test/test_def_macro.rb