defmacro 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +7 -1
- data/Manifest.txt +1 -0
- data/README.rdoc +1 -0
- data/README.txt +1 -0
- data/lib/def_macro.rb +3 -2
- data/lib/defmacro.rb +3 -0
- data/test/test_def_macro.rb +14 -1
- metadata +2 -1
data/History.txt
CHANGED
data/Manifest.txt
CHANGED
data/README.rdoc
CHANGED
data/README.txt
CHANGED
data/lib/def_macro.rb
CHANGED
@@ -2,7 +2,7 @@ require 'rubygems'
|
|
2
2
|
require 'ruby2ruby'
|
3
3
|
|
4
4
|
module DefMacro
|
5
|
-
VERSION = "0.0.
|
5
|
+
VERSION = "0.0.2"
|
6
6
|
|
7
7
|
def self.cleanse_body(body)
|
8
8
|
body = body.split("\n")
|
@@ -20,7 +20,8 @@ end
|
|
20
20
|
|
21
21
|
class Object
|
22
22
|
def def_macro(name,&body)
|
23
|
-
|
23
|
+
context = (self.kind_of?(Class) ? self : self.class)
|
24
|
+
context.class_eval <<-EOS
|
24
25
|
def #{name}(*args,&block)
|
25
26
|
mac_body = DefMacro.cleanse_body(block.to_ruby)
|
26
27
|
args.map! do |arg|
|
data/lib/defmacro.rb
ADDED
data/test/test_def_macro.rb
CHANGED
@@ -10,8 +10,13 @@ class Foo
|
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
13
|
+
def_macro :with do |args,body|
|
14
|
+
eval args.first
|
15
|
+
eval body
|
16
|
+
end
|
17
|
+
|
13
18
|
class TestDefMacro < Test::Unit::TestCase
|
14
|
-
def
|
19
|
+
def test_with_macro_in_class_def
|
15
20
|
foo = Foo.new
|
16
21
|
|
17
22
|
result = foo.with proc { a = 1; b = 3 } do
|
@@ -20,4 +25,12 @@ class TestDefMacro < Test::Unit::TestCase
|
|
20
25
|
|
21
26
|
assert_equal(4, result)
|
22
27
|
end
|
28
|
+
|
29
|
+
def test_with_macro_in_main
|
30
|
+
result = with proc { a = 1; b = 3 } do
|
31
|
+
a + b
|
32
|
+
end
|
33
|
+
|
34
|
+
assert_equal(4, result)
|
35
|
+
end
|
23
36
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: defmacro
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Drew Olson
|
@@ -57,6 +57,7 @@ files:
|
|
57
57
|
- README.txt
|
58
58
|
- Rakefile
|
59
59
|
- lib/def_macro.rb
|
60
|
+
- lib/defmacro.rb
|
60
61
|
- test/test_def_macro.rb
|
61
62
|
has_rdoc: true
|
62
63
|
homepage: http://github.com/dfg59/def_macro/tree/master
|