cant_even 2016.04.01

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 12c0c508188ce7063d82a17b6e66c1b54581a7c4
4
+ data.tar.gz: fd8aa02a4e8e9326ec526961d459985f75c51c04
5
+ SHA512:
6
+ metadata.gz: cacf2e808971302c0c833ca973ada1d007470ba9976deea9e17ef93a45f68dc444f54f8de86afd08ca8452eec34817e4d0b5bd77516a541c07c5604c6a1f675b
7
+ data.tar.gz: 759b1900c13d1ab2bfd037c46d0b8e56a8c0904d70fe00ecc630c184050e2e89d31c8a7cabc448698cd229fff3d18cd554dbd249438772b16f6e0c9ef945ee18
data/LICENSE ADDED
@@ -0,0 +1,13 @@
1
+ DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
2
+ Version 2, December 2004
3
+
4
+ Copyright (C) 2004 Sam Hocevar <sam@hocevar.net>
5
+
6
+ Everyone is permitted to copy and distribute verbatim or modified
7
+ copies of this license document, and changing it is allowed as long
8
+ as the name is changed.
9
+
10
+ DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
11
+ TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION, AND MODIFICATION
12
+
13
+ 0. You just DO WHAT THE FUCK YOU WANT TO.
data/README.md ADDED
@@ -0,0 +1,21 @@
1
+ # cant_even
2
+
3
+ Once loaded, **cant_even** makes it considerably more difficult to introduce dis[parity](https://en.wikipedia.org/wiki/Parity_(mathematics)) into your program.
4
+
5
+ ### "Usage"
6
+
7
+ ```ruby
8
+ 17 + 25
9
+ # => 42
10
+
11
+ require 'cant_even'
12
+
13
+ 17 + 25
14
+ # => Do you even return value? No, `42', you don't. (CantEven::ParityError)
15
+
16
+ 19 * 84
17
+ # => argument `84' has insufficient oddity.
18
+
19
+ 2016 / 12
20
+ # => `2016' is an inappropriately even receiver.
21
+ ```
data/Rakefile ADDED
@@ -0,0 +1,14 @@
1
+ require 'rake/testtask'
2
+
3
+ Rake::TestTask.new :spec do |t|
4
+ t.test_files = ['spec/cant_even_spec.rb']
5
+ end
6
+
7
+ task :default do
8
+ launcher = case RUBY_PLATFORM
9
+ when /darwin/i ; 'open'
10
+ when /win/i ; 'start'
11
+ else ; 'xdg-open'
12
+ end
13
+ `#{launcher} https://www.youtube.com/watch?v=dQw4w9WgXcQ`
14
+ end
data/cant_even.gemspec ADDED
@@ -0,0 +1,16 @@
1
+ $:.unshift File.expand_path '../lib', __FILE__
2
+ require 'cant_even/version'
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = 'cant_even'
6
+ s.version = CantEven::VERSION
7
+ s.author = 'D.E. Akers'
8
+ s.email = '0x0dea@gmail.com'
9
+
10
+ s.summary = 'A library for reducing disparity.'
11
+ s.homepage = 'https://github.com/0x0dea/cant_even'
12
+ s.license = 'WTFPL'
13
+
14
+ s.files = `git ls-files`.split
15
+ s.extensions = %w[Rakefile]
16
+ end
data/lib/cant_even.rb ADDED
@@ -0,0 +1,49 @@
1
+ module CantEven
2
+ ParityError = Class.new Exception
3
+ EscapeHatch = :i_suck_and_my_program_really_needs_to_even
4
+
5
+ # TODO: Moar!
6
+ NOPES = [
7
+ "%<kind>s `%<obj>d' has insufficient oddity.",
8
+ "`%<obj>d' is an inappropriately even %<kind>s.",
9
+ "Do you even %<kind>s? No, `%<obj>d', you don't.",
10
+ ]
11
+
12
+ def self.check obj, kind
13
+ if Integer === obj && obj.even?
14
+ raise ParityError,
15
+ NOPES.sample % {obj: obj, kind: kind},
16
+ # Scrub implementation details from the backtrace.
17
+ caller.grep_v(/Deoptimizer/).drop(kind == 'argument' ? 3 : 1)
18
+ end
19
+ end
20
+
21
+ # Trace calls and returns, and explode if any evens are involved.
22
+ # Unexported and immediately enabled for maximal topkeks.
23
+ tracer = TracePoint.new(:call, :c_call, :return, :c_return) { |tp|
24
+ case tp.event
25
+ when :call, :c_call
26
+ check tp.self, 'receiver'
27
+ tp.binding.local_variables.each do |lv|
28
+ check tp.binding.local_variable_get(lv), 'argument'
29
+ end
30
+ when :return, :c_return
31
+ check tp.return_value, 'return value'
32
+ end
33
+ }.tap(&:enable)
34
+
35
+ # Close over ^ to provide an escape hatch for dire circumstances.
36
+ define_singleton_method(EscapeHatch) { |&block|
37
+ tracer.disable and block.call and tracer.enable
38
+ }
39
+
40
+ # `1 + 1` compiles to `opt_plus` and won't be seen by TracePoint
41
+ # as long as Fixnum#+ has its original definition.
42
+ module Deoptimizer
43
+ %i[+ - * / % < <= > >= ==].each do |op|
44
+ define_method(op) { |o| super o }
45
+ end
46
+ end
47
+ end
48
+
49
+ Fixnum.prepend CantEven::Deoptimizer
@@ -0,0 +1,3 @@
1
+ module CantEven
2
+ VERSION = '2016.04.01'
3
+ end
@@ -0,0 +1,8 @@
1
+ require 'minitest/autorun'
2
+ require 'cant_even'
3
+
4
+ describe CantEven do
5
+ it 'is very hard to test' do
6
+ # ???
7
+ end
8
+ end
metadata ADDED
@@ -0,0 +1,51 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cant_even
3
+ version: !ruby/object:Gem::Version
4
+ version: 2016.04.01
5
+ platform: ruby
6
+ authors:
7
+ - D.E. Akers
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-04-01 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description:
14
+ email: 0x0dea@gmail.com
15
+ executables: []
16
+ extensions:
17
+ - Rakefile
18
+ extra_rdoc_files: []
19
+ files:
20
+ - LICENSE
21
+ - README.md
22
+ - Rakefile
23
+ - cant_even.gemspec
24
+ - lib/cant_even.rb
25
+ - lib/cant_even/version.rb
26
+ - spec/cant_even_spec.rb
27
+ homepage: https://github.com/0x0dea/cant_even
28
+ licenses:
29
+ - WTFPL
30
+ metadata: {}
31
+ post_install_message:
32
+ rdoc_options: []
33
+ require_paths:
34
+ - lib
35
+ required_ruby_version: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ required_rubygems_version: !ruby/object:Gem::Requirement
41
+ requirements:
42
+ - - ">="
43
+ - !ruby/object:Gem::Version
44
+ version: '0'
45
+ requirements: []
46
+ rubyforge_project:
47
+ rubygems_version: 2.6.2
48
+ signing_key:
49
+ specification_version: 4
50
+ summary: A library for reducing disparity.
51
+ test_files: []