defmacro 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/History.txt CHANGED
@@ -1,6 +1,12 @@
1
+ === 0.0.2 / 2008-06-11
2
+
3
+ * 1 minor enhancement
4
+
5
+ * macros can be defined on objects or on main
6
+
1
7
  === 0.0.1 / 2008-06-09
2
8
 
3
9
  * 1 major enhancement
4
10
 
5
- * Birthday!
11
+ * macros!
6
12
 
data/Manifest.txt CHANGED
@@ -4,4 +4,5 @@ README.rdoc
4
4
  README.txt
5
5
  Rakefile
6
6
  lib/def_macro.rb
7
+ lib/defmacro.rb
7
8
  test/test_def_macro.rb
data/README.rdoc CHANGED
@@ -42,6 +42,7 @@ Macros for ruby
42
42
  == INSTALL:
43
43
 
44
44
  * sudo gem install dfg59-def_macro --source=http://gems.github.com
45
+ * sudo gem install defmacro
45
46
 
46
47
  == LICENSE:
47
48
 
data/README.txt CHANGED
@@ -42,6 +42,7 @@ Macros for ruby
42
42
  == INSTALL:
43
43
 
44
44
  * sudo gem install dfg59-def_macro --source=http://gems.github.com
45
+ * sudo gem install defmacro
45
46
 
46
47
  == LICENSE:
47
48
 
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.1"
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
- class_eval <<-EOS
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
@@ -0,0 +1,3 @@
1
+ require 'rubygems'
2
+ require 'need'
3
+ need { "def_macro" }
@@ -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 test_with_macro
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.1
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