Permalink
Browse files

adjust

  • Loading branch information...
1 parent 7503298 commit a5cbc544b9e3013ab4b3ea1b335835aef9d0ecd7 @kachick committed May 20, 2012
Showing with 35 additions and 36 deletions.
  1. +1 −0 Manifest.txt
  2. +20 −25 lib/vertere.rb
  3. +9 −11 lib/vertere/ext.rb
  4. +5 −0 lib/vertere/version.rb
View
@@ -5,6 +5,7 @@ Manifest.txt
Rakefile
example.rb
lib/vertere.rb
+lib/vertere/version.rb
lib/vertere/ext.rb
test/test_helper.rb
test/test_vertere.rb
View
@@ -1,44 +1,39 @@
# Copyright (C) 2012 Kenichi Kamiya
require 'delegate'
+require_relative 'vertere/version'
module Vertere
- VERSION = '0.0.2'.freeze
-
class << self
def for_object(original)
- invereted = original.clone
- rescue SecurityError
- invereted = original.dup
- rescue TypeError
- invereted = SimpleDelegator.new original
- ensure
- invereted.singleton_class.class_eval do
- %w[== === =~].each do |operator|
- if original.respond_to? operator
- define_method operator do |other|
- ! (super other)
+ SimpleDelegator.new(original).tap {|wrapper|
+ wrapper.singleton_class.class_eval do
+ [:==, :===, :=~].each do |operator|
+ if original.respond_to? operator
+ define_method operator do |other|
+ ! (super other)
+ end
end
end
- end
-
- if original.respond_to? :<=>
- def <=>(other)
- r = super other
- r && (- r)
+
+ if original.respond_to? :<=>
+ def <=>(other)
+ r = super other
+ r && (- r)
+ end
+ end
+
+ def comparison_inverted?
+ true
end
end
-
- def comparison_inverted?
- true
- end
- end
+ }
end
alias_method :invert, :for_object
end
-end
+end
View
@@ -1,15 +1,13 @@
-module Vertere
+module Vertere::ObjectExtension
- module ObjectExtension
- def for_vertere
- ::Vertere.for_object self
- end
-
- alias_method :for_!, :for_vertere
-
- def comparison_inverted?
- false
- end
+ def for_vertere
+ ::Vertere.for_object self
+ end
+
+ alias_method :for_!, :for_vertere
+
+ def comparison_inverted?
+ false
end
end
View
@@ -0,0 +1,5 @@
+module Vertere
+
+ VERSION = '0.0.2'.freeze
+
+end

0 comments on commit a5cbc54

Please sign in to comment.