Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

cleaning

  • Loading branch information...
commit 717fd5f27b615aec4bcb762128b703c62ccaae2d 1 parent 2bbda18
@kachick authored
View
26 .gitignore
@@ -0,0 +1,26 @@
+*.gem
+*.rbc
+.bundle
+.config
+coverage
+coverage.data
+InstalledFiles
+lib/bundler/man
+pkg
+rdoc
+spec/reports
+test/tmp
+test/version_tmp
+tmp
+
+# YARD artifacts
+.yardoc
+_yardoc
+doc/
+
+# tmp-old
+.old
+
+# editor
+*~
+.redcar
View
22 LICENSE
@@ -0,0 +1,22 @@
+(The MIT X11 License)
+
+Copyright (c) 2012 Kenichi Kamiya
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+'Software'), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
View
3  Manifest.txt
@@ -1,6 +1,7 @@
+README.rdoc
+LICENSE
History.rdoc
Manifest.txt
-README.rdoc
Rakefile
example.rb
lib/vertere/core.rb
View
82 README.rdoc
@@ -1,66 +1,60 @@
= vertere
-* http://github.com/kachick/vertere
-* https://rubygems.org/gems/vertere
-* http://rubyforge.org/projects/vertere
+code :: http://github.com/kachick/vertere
+gem :: http://rubygems.org/gems/vertere
-== DESCRIPTION
+== Description
-wrapper for inverted comparisons
+Provide a wrapper class for inverted comparisons
-== FEATURES
-* easy get objects for inverted comparisons
+== Features
-== SYNOPSIS
+Wrap below methods
-* setup
- require 'vertere'
+* #==
+* #===
+* #=~
+* #<=>
+
+== Usage
-* an approach for [ruby-talk:392128]
- # http://www.ruby-forum.com/topic/3418285
+* Setup
+
+ require 'vertere'
- NUMBER_CHARS=('0'..'11').map(&:freeze).freeze
- #=> ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11"]
+* An approaching to invert comparisons # from [ruby-talk:392128]
- NUMBER_CHARS.grep(/0/)
- #=> ["0", "10"]
+ NUMBER_CHARS = ["0", "1", "9", "10", "11"]
+ NUMBER_CHARS.grep(/0/) #=> ["0", "10"]
+ NUMBER_CHARS.grep(Veretere.invert(/0/)) #=> ["1", "9", "11"]
+
+* Extend Ruby's interface
- NUMBER_CHARS.grep(/0/.for_!)
- #=> ["1", "2", "3", "4", "5", "6", "7", "8", "9", "11"]
+ require 'vertere/ext'
-* and more
- NUMBER_CHARS.sort_by{|s|s.to_i.for_!}
- #=> ["11", "10", "9", "8", "7", "6", "5", "4", "3", "2", "1", "0"]
+ NUMBER_CHARS.grep(/0/.for_!) #=> ["1", "9", "11"]
-== REQUIREMENTS
+* And more
-* Ruby 1.9.2 and later (tested 1.9.2, 1.9.3)
+ NUMBER_CHARS.sort_by{|s|s.to_i.for_!} #=> ["11", "10", "9", "1", "0"]
-== INSTALL
+== Requirements
-* sudo gem install vertere
+* Ruby 1.9.2 or later
+
+ Focusing
+
+ * 1.9.3-p194
+ * 1.9.2-p290
-== LICENSE
+== Installation
-(The MIT License)
+* gem install vertere
-Copyright (c) 2012 Kenichi Kamiya
+== License
-Permission is hereby granted, free of charge, to any person obtaining
-a copy of this software and associated documentation files (the
-'Software'), to deal in the Software without restriction, including
-without limitation the rights to use, copy, modify, merge, publish,
-distribute, sublicense, and/or sell copies of the Software, and to
-permit persons to whom the Software is furnished to do so, subject to
-the following conditions:
+The MIT X11 License
-The above copyright notice and this permission notice shall be
-included in all copies or substantial portions of the Software.
+Copyright (c) 2012 Kenichi Kamiya
-THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
-EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
-IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
-CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
-TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
-SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+See the file LICENSE for further details.
View
17 Rakefile
@@ -1,24 +1,15 @@
-require 'rubygems'
-gem 'hoe', '>= 2.12.4'
+gem 'hoe', '~> 3.0.6'
require 'hoe'
require 'fileutils'
Hoe.plugin :newgem
-# Hoe.plugin :website
-# Hoe.plugin :cucumberfeatures
-# Generate all the Rake tasks
-# Run 'rake -T' to see list of generated tasks (from gem root directory)
$hoe = Hoe.spec 'vertere' do
developer 'Kenichi Kamiya', 'kachick1+ruby@gmail.com'
- self.rubyforge_name = self.name
+ self.rubyforge_name = name
require_ruby_version '>= 1.9.2'
- dependency 'yard', '~> 0.7.4', :development
+ dependency 'yard', '~> 0.8.1', :development
end
require 'newgem/tasks'
-Dir['tasks/**/*.rake'].each { |t| load t }
-
-# TODO - want other tests/tasks run by default? Add them to the list
-# remove_task :default
-# task :default => [:spec, :features]
+Dir['tasks/**/*.rake'].each { |t| load t }
View
7 example.rb
@@ -2,13 +2,16 @@
require_relative 'lib/vertere'
-# an approach for [ruby-talk:392128]
+# An approach for [ruby-talk:392128]
# http://www.ruby-forum.com/topic/3418285
-NUMBER_CHARS=('0'..'11').map(&:freeze).freeze
+NUMBER_CHARS = ('0'..'11').map(&:freeze).freeze
p NUMBER_CHARS
p NUMBER_CHARS.grep(/0/)
p(/0/ =~ '0')
+
+require_relative 'lib/vertere/ext'
+
p NUMBER_CHARS.grep(/0/.for_!)
p(/0/.for_! =~ '0')
p NUMBER_CHARS.grep(/0/)
View
46 lib/vertere.rb
@@ -1,4 +1,44 @@
-# Copyright (C) 2012 Kenichi Kamiya
+# Copyright (C) 2012 Kenichi Kamiya
-require_relative 'vertere/core'
-require_relative 'vertere/import'
+require 'delegate'
+
+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)
+ end
+ end
+ end
+
+ if original.respond_to? :<=>
+ def <=>(other)
+ r = super other
+ r && (- r)
+ end
+ end
+
+ def comparison_inverted?
+ true
+ end
+ end
+ end
+
+ alias_method :invert, :for_object
+
+ end
+
+end
View
22 lib/vertere/ext.rb
@@ -0,0 +1,22 @@
+module Vertere
+
+ module ObjectExtension
+ def for_vertere
+ ::Vertere.for_object self
+ end
+
+ alias_method :for_!, :for_vertere
+
+ def comparison_inverted?
+ false
+ end
+ end
+
+end
+
+
+class Object
+
+ include Vertere::ObjectExtension
+
+end
View
5 lib/vertere/import.rb
@@ -1,5 +0,0 @@
-require_relative 'core'
-
-class Object
- include Vertere::ObjectExtension
-end
View
4 test/test_helper.rb
@@ -1,3 +1,3 @@
-require 'stringio'
require 'test/unit'
-require File.dirname(__FILE__) + '/../lib/vertere'
+require_relative '../lib/vertere'
+require_relative '../lib/vertere/ext'
View
5 test/test_vertere.rb
@@ -1,11 +1,12 @@
$VERBOSE = true
-require File.dirname(__FILE__) + '/test_helper.rb'
+require_relative 'test_helper'
class TestVertere < Test::Unit::TestCase
- NUMBER_CHARS=('0'..'11').map(&:freeze).freeze
+ NUMBER_CHARS = ('0'..'11').map(&:freeze).freeze
def test_compare
assert_equal(["0", "10"], NUMBER_CHARS.grep(/0/))
+ assert_equal((NUMBER_CHARS - ["0", "10"]), NUMBER_CHARS.grep(Vertere.invert(/0/)))
assert_equal((NUMBER_CHARS - ["0", "10"]), NUMBER_CHARS.grep(/0/.for_!))
assert_equal(false, (/0/.for_! =~ '0'))
assert_equal(["0", "10"], NUMBER_CHARS.grep(/0/)) # check not bloken
Please sign in to comment.
Something went wrong with that request. Please try again.