unextendable 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,9 @@
1
1
  = Unextendable CHANGELOG
2
2
 
3
+ == Version 0.1.1 (May 1, 2011)
4
+
5
+ * Being able to pass a block to 'unextend' and only unextending a module when the block passes
6
+
3
7
  == Version 0.1.0 (May 1, 2011)
4
8
 
5
9
  * Initial release
@@ -14,7 +14,7 @@ A gem that allows objects to effectively mixin and unmix modules. The downside i
14
14
 
15
15
  *Evil-ruby* - "Github repository":https://github.com/yugui/evil-ruby
16
16
 
17
- A gem that extends Ruby's semantics by accessing its internals from pure Ruby code. I do not want to mess with Ruby internals too much just for what I want to implement. As the name already, is it ethical or just evil? I will let you judge that. By the way, "evilr":https://github.com/jeremyevans/evilr is its brother written in C.
17
+ A gem that extends Ruby's semantics by accessing its internals from pure Ruby code. I do not want to mess with Ruby internals too much just for what I want to implement. As the name already says, is it ethical or just evil? I will let you judge that. By the way, "evilr":https://github.com/jeremyevans/evilr is its brother written in C.
18
18
 
19
19
  *StatePattern* - "Github repository":https://github.com/dcadenas/state_pattern
20
20
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.1.1
@@ -26,12 +26,14 @@ class Object
26
26
  end
27
27
  end
28
28
 
29
- def unextend(*modules)
29
+ def unextend(*modules, &block)
30
30
  if modules.empty?
31
- meta_class.extended_modules.delete_if{|mod| mod.unextendable?}
31
+ meta_class.extended_modules.delete_if do |mod|
32
+ mod.unextendable? if !block_given? || block.call(mod)
33
+ end
32
34
  else
33
35
  modules.each do |mod|
34
- meta_class.extended_modules.delete mod
36
+ meta_class.extended_modules.delete mod if !block_given? || block.call(mod)
35
37
  end
36
38
  end
37
39
  end
@@ -1,3 +1,7 @@
1
1
  module Unextendable
2
- VERSION = "0.1.0"
2
+ MAJOR = 0
3
+ MINOR = 1
4
+ TINY = 1
5
+
6
+ VERSION = [MAJOR, MINOR, TINY].join(".")
3
7
  end
@@ -143,6 +143,23 @@ class ObjectInstanceTest < Test::Unit::TestCase
143
143
  assert !@c.meta_class.extended_modules.include?(U)
144
144
  end
145
145
 
146
+ should "remove the module but when passed a block only when it passes" do
147
+ assert_equal "Mr. C", @c.salutation
148
+
149
+ @c.extend U
150
+ assert_equal "Mr. U", @c.salutation
151
+
152
+ @c.unextend do |mod|
153
+ mod != U
154
+ end
155
+ assert_equal "Mr. U", @c.salutation
156
+
157
+ @c.unextend do |mod|
158
+ mod == U
159
+ end
160
+ assert_equal "Mr. C", @c.salutation
161
+ end
162
+
146
163
  context "when calling an unextendable method" do
147
164
  should "match the expected method" do
148
165
  assert_equal @c.method(:name), @c.send(:method_for, :name)
@@ -207,6 +224,17 @@ class ObjectInstanceTest < Test::Unit::TestCase
207
224
 
208
225
  @c.unextend
209
226
  assert_equal "Ms. A", @c.salutation
227
+
228
+ @c.extend U
229
+ @c.unextend do |mod|
230
+ mod != U
231
+ end
232
+ assert_equal "Ms. U", @c.salutation
233
+
234
+ @c.unextend do |mod|
235
+ mod == U
236
+ end
237
+ assert_equal "Ms. A", @c.salutation
210
238
  end
211
239
  end
212
240
  end
@@ -10,7 +10,7 @@ Gem::Specification.new do |s|
10
10
  s.email = ["paul.engel@holder.nl"]
11
11
  s.homepage = "https://github.com/archan937/unextendable"
12
12
  s.summary = %q{A small gem making unextending extended module methods within object instances possible}
13
- s.description = %q{Unextendable originated from the thought of being able to implement the "State pattern":http://tobyho.com/Design_Patterns_Revisited%3A_State within object instances using modules. In other words: I wanted object instances to behave dependent on their state using modules. I really want to use modules because they are commonly used to define a set of methods which you can extend within an object instance. Unfortunately, you cannot just unexclude a module. So after searching the web for solutions, I came across Mixology, evil-ruby and StatePattern. But they slightly did not fit the picture. So after doing some research, I came up with Unextendable.}
13
+ s.description = %q{Unextendable originated from the thought of being able to implement the State pattern within object instances using modules. In other words: I wanted object instances to behave dependent on their state using modules. I really want to use modules because they are commonly used to define a set of methods which you can extend within an object instance. Unfortunately, you cannot just unexclude a module. So after searching the web for solutions, I came across Mixology, evil-ruby and StatePattern. But they slightly did not fit the picture. So after doing some research, I came up with Unextendable.}
14
14
 
15
15
  s.rubyforge_project = "unextendable"
16
16
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: unextendable
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 25
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 0
10
- version: 0.1.0
9
+ - 1
10
+ version: 0.1.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Paul Engel
@@ -46,7 +46,7 @@ dependencies:
46
46
  version: "0"
47
47
  type: :development
48
48
  version_requirements: *id002
49
- description: "Unextendable originated from the thought of being able to implement the \"State pattern\":http://tobyho.com/Design_Patterns_Revisited%3A_State within object instances using modules. In other words: I wanted object instances to behave dependent on their state using modules. I really want to use modules because they are commonly used to define a set of methods which you can extend within an object instance. Unfortunately, you cannot just unexclude a module. So after searching the web for solutions, I came across Mixology, evil-ruby and StatePattern. But they slightly did not fit the picture. So after doing some research, I came up with Unextendable."
49
+ description: "Unextendable originated from the thought of being able to implement the State pattern within object instances using modules. In other words: I wanted object instances to behave dependent on their state using modules. I really want to use modules because they are commonly used to define a set of methods which you can extend within an object instance. Unfortunately, you cannot just unexclude a module. So after searching the web for solutions, I came across Mixology, evil-ruby and StatePattern. But they slightly did not fit the picture. So after doing some research, I came up with Unextendable."
50
50
  email:
51
51
  - paul.engel@holder.nl
52
52
  executables: []