use 1.3.0 → 1.3.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (6) hide show
  1. data/CHANGES +5 -0
  2. data/README +8 -6
  3. data/lib/use.rb +16 -15
  4. data/test/sample_data.rb +15 -0
  5. data/test/test_use.rb +12 -1
  6. metadata +2 -2
data/CHANGES CHANGED
@@ -1,3 +1,8 @@
1
+ == 1.3.1 - 31-Jul-2009
2
+ * Fixed a bug where identical methods from different modules were being
3
+ inadvertently undefined.
4
+ * Updated the main rdoc example and fixed a typo in the README synopsis.
5
+
1
6
  == 1.3.0 - 30-Jul-2009
2
7
  * Compatibility fixes for Ruby 1.9.x
3
8
  * Added structured_warnings as a dependency, and now emits a
data/README CHANGED
@@ -16,21 +16,23 @@
16
16
  rake install_gem
17
17
 
18
18
  == Synopsis
19
+ require 'use'
20
+
19
21
  module Foo
20
22
  def bar
21
- "hello"
23
+ puts "hello"
22
24
  end
23
25
  def baz
24
- "world"
26
+ puts "world"
25
27
  end
26
28
  end
27
29
 
28
30
  module Test
29
31
  def bar
30
- "goodbye"
32
+ puts "goodbye"
31
33
  end
32
34
  def blah
33
- "new york"
35
+ puts "new york"
34
36
  end
35
37
  end
36
38
 
@@ -42,12 +44,12 @@
42
44
  z = Zap.new
43
45
 
44
46
  z.bar # => "hello"
47
+ z.blah # => "new york"
45
48
  z.baz # => NoMethodError
46
- z.blah # =>"new york"
47
49
 
48
50
  # Using the new keywords
49
51
  class MyKlass
50
- use Foo :alias => {:bar => :test}
52
+ use Foo, :alias => {:bar => :test}
51
53
  end
52
54
 
53
55
  m = MyKlass.new
data/lib/use.rb CHANGED
@@ -8,7 +8,7 @@ end
8
8
 
9
9
  class Class
10
10
  # The version of the 'use' library
11
- USE_VERSION = '1.3.0'
11
+ USE_VERSION = '1.3.1'
12
12
 
13
13
  # Allows you to include mixins in a fine grained manner. Instead of
14
14
  # including all methods from a given module, you can can instead mixin
@@ -18,33 +18,33 @@ class Class
18
18
  # Examples:
19
19
  #
20
20
  # # Defines a 'bar' and 'baz' method
21
- # module Foo
21
+ # module Alpha
22
22
  # def bar
23
- # "hello"
23
+ # puts 'hello'
24
24
  # end
25
25
  # def baz
26
- # "world"
26
+ # puts 'world'
27
27
  # end
28
28
  # end
29
29
  #
30
30
  # # Defines a 'bar', 'blah', and 'zap' methods
31
- # module Test
31
+ # module Beta
32
32
  # def bar
33
- # "goodbye"
33
+ # puts 'goodbye'
34
34
  # end
35
35
  # def blah
36
- # "new york"
36
+ # puts 'new york'
37
37
  # end
38
38
  # def zap
39
- # "zap"
39
+ # puts 'zap'
40
40
  # end
41
41
  # end
42
42
  #
43
- # # From the Foo module, only mixin the 'bar' method. From the Test
43
+ # # From the Alpha module, only mixin the 'bar' method. From the Beta
44
44
  # # module exclude the 'bar' and 'zap' methods.
45
45
  # class Zap
46
- # use Foo, :bar
47
- # use Test, :exclude => [:bar, :zap]
46
+ # use Alpha, :bar
47
+ # use Beta, :exclude => [:bar, :zap]
48
48
  # end
49
49
  #
50
50
  # z = Zap.new
@@ -52,15 +52,15 @@ class Class
52
52
  # z.bar # => "hello"
53
53
  # z.baz # => NoMethodError - wasn't mixed in
54
54
  # z.zap # => NoMethodError - wasn't mixed in
55
- # z.blah # =>"new york"
55
+ # z.blah # => "new york"
56
56
  #
57
57
  # # Alias a method on the fly
58
58
  # class MyKlass
59
- # use Foo :alias => {:bar, :test}
59
+ # use Alpha, :alias => {:bar, :test}
60
60
  # end
61
61
  #
62
62
  # m = MyKlass.new
63
- # m.test # => "hello"
63
+ # m.test # => 'hello'
64
64
  # m.bar # => NoMethodError - was aliased to 'test'
65
65
  #
66
66
  # If no options follow the module name this method is identical
@@ -147,8 +147,9 @@ class Class
147
147
  # remove methods from classes that already exist unless specifically
148
148
  # included.
149
149
  unless included_methods.empty?
150
+ self_instance_methods = self.instance_methods.map{ |e| e.to_s }
150
151
  (local_instance_methods - included_methods).each{ |meth|
151
- if superclass.instance_methods.include?(meth)
152
+ if self_instance_methods.include?(meth)
152
153
  if included_methods.include?(meth)
153
154
  mod.module_eval{ undef_method(meth) rescue nil }
154
155
  else
data/test/sample_data.rb CHANGED
@@ -42,6 +42,16 @@ module ModC
42
42
  end
43
43
  end
44
44
 
45
+ module ModD
46
+ def meth_a
47
+ "ModD#meth_a"
48
+ end
49
+
50
+ def meth_b
51
+ "ModD#meth_b"
52
+ end
53
+ end
54
+
45
55
  class ClassA
46
56
  use ModA, :meth_a
47
57
  end
@@ -64,3 +74,8 @@ class ClassD
64
74
  :alias => {:meth_a => :meth_x, :meth_c => :meth_z},
65
75
  :exclude => :meth_b
66
76
  end
77
+
78
+ class ClassE
79
+ use ModA, :meth_a
80
+ use ModD, :meth_b
81
+ end
data/test/test_use.rb CHANGED
@@ -15,6 +15,7 @@ class TC_Use < Test::Unit::TestCase
15
15
  @b = ClassB.new
16
16
  @c = ClassC.new
17
17
  @d = ClassD.new
18
+ @e = ClassE.new
18
19
  end
19
20
 
20
21
  # Convert symbols to strings for 1.9.x
@@ -24,7 +25,7 @@ class TC_Use < Test::Unit::TestCase
24
25
  end
25
26
 
26
27
  def test_version
27
- assert_equal('1.3.0', Class::USE_VERSION)
28
+ assert_equal('1.3.1', Class::USE_VERSION)
28
29
  end
29
30
 
30
31
  def test_mod_a_methods
@@ -39,6 +40,10 @@ class TC_Use < Test::Unit::TestCase
39
40
  assert_methods(['meth_x', 'meth_y', 'meth_z'], ModC.instance_methods.sort)
40
41
  end
41
42
 
43
+ def test_mod_d_methods
44
+ assert_methods(['meth_a', 'meth_b'], ModD.instance_methods.sort)
45
+ end
46
+
42
47
  def test_class_a_methods
43
48
  assert_respond_to(@a, :meth_a)
44
49
  assert_equal('ModA#meth_a', @a.meth_a)
@@ -93,10 +98,16 @@ class TC_Use < Test::Unit::TestCase
93
98
  assert_raise(NoMethodError){ @d.meth_c }
94
99
  end
95
100
 
101
+ def test_class_e_methods
102
+ assert_respond_to(@e, :meth_a)
103
+ assert_respond_to(@e, :meth_b)
104
+ end
105
+
96
106
  def teardown
97
107
  @a = nil
98
108
  @b = nil
99
109
  @c = nil
100
110
  @d = nil
111
+ @e = nil
101
112
  end
102
113
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: use
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0
4
+ version: 1.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel J. Berger
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-07-30 00:00:00 -06:00
12
+ date: 2009-07-31 00:00:00 -06:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency