discombobulator 0.0.1 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/Gemfile +0 -1
- data/README.md +9 -23
- data/discombobulator.gemspec +6 -7
- data/lib/discombobulator.rb +25 -3
- data/lib/discombobulator/config.rb +13 -0
- data/lib/discombobulator/dodge_attack.rb +8 -0
- data/lib/discombobulator/super_call.rb +26 -0
- data/lib/discombobulator/super_polymorphic.rb +31 -0
- data/lib/discombobulator/swap_globals.rb +30 -0
- metadata +29 -17
- checksums.yaml +0 -7
- data/lib/discombobulator/version.rb +0 -3
data/.gitignore
CHANGED
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,29 +1,15 @@
|
|
1
1
|
# Discombobulator
|
2
2
|
|
3
|
-
|
3
|
+
https://github.com/obrok/discombobulator
|
4
4
|
|
5
|
-
|
5
|
+
Don't you hate seeing this in your face when working on your next $1,000,000,000 startup idea?
|
6
6
|
|
7
|
-
|
7
|
+
```
|
8
|
+
NoMethodError: undefined method `+' for nil:NilClass
|
9
|
+
```
|
8
10
|
|
9
|
-
|
11
|
+
Well fear no more, discombobulator is here to save the day!
|
10
12
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
Or install it yourself as:
|
16
|
-
|
17
|
-
$ gem install discombobulator
|
18
|
-
|
19
|
-
## Usage
|
20
|
-
|
21
|
-
TODO: Write usage instructions here
|
22
|
-
|
23
|
-
## Contributing
|
24
|
-
|
25
|
-
1. Fork it ( http://github.com/<my-github-username>/discombobulator/fork )
|
26
|
-
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
-
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
-
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
-
5. Create new Pull Request
|
13
|
+
```
|
14
|
+
gem 'discombobulator'
|
15
|
+
```
|
data/discombobulator.gemspec
CHANGED
@@ -1,15 +1,14 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
lib = File.expand_path('../lib', __FILE__)
|
3
3
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
require 'discombobulator/version'
|
5
4
|
|
6
5
|
Gem::Specification.new do |spec|
|
7
6
|
spec.name = "discombobulator"
|
8
|
-
spec.version =
|
9
|
-
spec.authors = ["Paweł Obrok"]
|
10
|
-
spec.email = ["pawel.obrok@gmail.com"]
|
11
|
-
spec.summary =
|
12
|
-
spec.description =
|
7
|
+
spec.version = "0.1.0"
|
8
|
+
spec.authors = ["Paweł Obrok", "Norbert Wojtowicz"]
|
9
|
+
spec.email = ["pawel.obrok@gmail.com", "wojtowicz.norbert@gmail.com"]
|
10
|
+
spec.summary = "Discombobulate for the greater good!"
|
11
|
+
spec.description = spec.summary
|
13
12
|
spec.homepage = ""
|
14
13
|
spec.license = "MIT"
|
15
14
|
|
@@ -18,6 +17,6 @@ Gem::Specification.new do |spec|
|
|
18
17
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
18
|
spec.require_paths = ["lib"]
|
20
19
|
|
21
|
-
spec.add_development_dependency "bundler", "
|
20
|
+
spec.add_development_dependency "bundler", ">= 1.3"
|
22
21
|
spec.add_development_dependency "rake"
|
23
22
|
end
|
data/lib/discombobulator.rb
CHANGED
@@ -1,5 +1,27 @@
|
|
1
|
-
|
1
|
+
$DISCOMBOBULATOR_SAFETY_FEATURE = 42
|
2
2
|
|
3
|
-
|
4
|
-
# Your code goes here...
|
3
|
+
class Discombobulator < BasicObject
|
5
4
|
end
|
5
|
+
|
6
|
+
require "discombobulator/config"
|
7
|
+
|
8
|
+
class Discombobulator < BasicObject
|
9
|
+
def self.method_missing(meth, *args, &block)
|
10
|
+
self.new.method_missing(meth, *args, &block)
|
11
|
+
end
|
12
|
+
|
13
|
+
def method_missing(meth, *args, &block)
|
14
|
+
plugin = plugins.sample
|
15
|
+
plugin.call(meth, *args, &block)
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
def plugins
|
20
|
+
::Discombobulator::Config.instance.plugins
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
require "discombobulator/dodge_attack"
|
25
|
+
require "discombobulator/super_call"
|
26
|
+
require "discombobulator/swap_globals"
|
27
|
+
require "discombobulator/super_polymorphic"
|
@@ -0,0 +1,26 @@
|
|
1
|
+
class Discombobulator::SuperCall
|
2
|
+
def self.call(meth, *args, &block)
|
3
|
+
self.new.call(meth, *args, &block)
|
4
|
+
end
|
5
|
+
|
6
|
+
def call(meth, *args, &block)
|
7
|
+
method = find_me_a_method(args.length)
|
8
|
+
if $DISCOMBOBULATOR_SAFETY_FEATURE == 42
|
9
|
+
p "CALLING: #{method.name} with #{args.inspect}"
|
10
|
+
else
|
11
|
+
method.call(*args, &block)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
def find_me_a_method(arity)
|
17
|
+
ObjectSpace.each_object.to_a.shuffle.each do |obj|
|
18
|
+
obj.methods.shuffle.each do |name|
|
19
|
+
method = obj.method(name)
|
20
|
+
return method if method.arity == arity
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
Discombobulator::Config.instance.add_plugin(Discombobulator::SuperCall)
|
@@ -0,0 +1,31 @@
|
|
1
|
+
class Discombobulator::SuperPolymorphic
|
2
|
+
def self.call(meth, *args, &block)
|
3
|
+
self.new.call(meth, *args, &block)
|
4
|
+
end
|
5
|
+
|
6
|
+
def call(meth, *args, &block)
|
7
|
+
method = find_me_a_method(meth, args.length)
|
8
|
+
no_method_error(meth) unless method
|
9
|
+
if $DISCOMBOBULATOR_SAFETY_FEATURE == 42
|
10
|
+
p "Calling the BEST '##{method.name}' with #{args.inspect}"
|
11
|
+
else
|
12
|
+
method.call(*args, &block)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
def no_method_error(name)
|
18
|
+
raise NoMethodError, "Dude, what have you been smoking? I could not find a single appropriate '#{name}' to call."
|
19
|
+
end
|
20
|
+
|
21
|
+
def find_me_a_method(name, arity)
|
22
|
+
name = name.to_sym
|
23
|
+
ObjectSpace.each_object.to_a.shuffle.each do |obj|
|
24
|
+
method = obj.method(name) rescue nil
|
25
|
+
return method if method && method.arity == arity
|
26
|
+
end
|
27
|
+
nil
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
Discombobulator::Config.instance.add_plugin(Discombobulator::SuperPolymorphic)
|
@@ -0,0 +1,30 @@
|
|
1
|
+
class Discombobulator::SwapGlobals
|
2
|
+
def self.call(meth, *args, &block)
|
3
|
+
self.new.call(meth, *args, &block)
|
4
|
+
end
|
5
|
+
|
6
|
+
def call(meth, *args, &block)
|
7
|
+
name1, name2 = global_variables.shuffle.take(2)
|
8
|
+
val1, val2 = get_global(name1), get_global(name2)
|
9
|
+
set_global(name1, val2)
|
10
|
+
set_global(name2, val1)
|
11
|
+
Discombobulator.new
|
12
|
+
rescue NameError, SyntaxError, TypeError, ArgumentError
|
13
|
+
retry
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
def get_global(name)
|
18
|
+
eval(name.to_s)
|
19
|
+
end
|
20
|
+
|
21
|
+
def set_global(name, value)
|
22
|
+
if $DISCOMBOBULATOR_SAFETY_FEATURE == 42
|
23
|
+
puts "Setting global #{name} to #{value.inspect}"
|
24
|
+
else
|
25
|
+
eval("#{name} = value")
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
Discombobulator::Config.instance.add_plugin(Discombobulator::SwapGlobals)
|
metadata
CHANGED
@@ -1,81 +1,93 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: discombobulator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
5
6
|
platform: ruby
|
6
7
|
authors:
|
7
8
|
- Paweł Obrok
|
9
|
+
- Norbert Wojtowicz
|
8
10
|
autorequire:
|
9
11
|
bindir: bin
|
10
12
|
cert_chain: []
|
11
|
-
date: 2014-03-
|
13
|
+
date: 2014-03-21 00:00:00.000000000 Z
|
12
14
|
dependencies:
|
13
15
|
- !ruby/object:Gem::Dependency
|
14
16
|
name: bundler
|
15
17
|
requirement: !ruby/object:Gem::Requirement
|
18
|
+
none: false
|
16
19
|
requirements:
|
17
|
-
- -
|
20
|
+
- - ! '>='
|
18
21
|
- !ruby/object:Gem::Version
|
19
|
-
version: '1.
|
22
|
+
version: '1.3'
|
20
23
|
type: :development
|
21
24
|
prerelease: false
|
22
25
|
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
none: false
|
23
27
|
requirements:
|
24
|
-
- -
|
28
|
+
- - ! '>='
|
25
29
|
- !ruby/object:Gem::Version
|
26
|
-
version: '1.
|
30
|
+
version: '1.3'
|
27
31
|
- !ruby/object:Gem::Dependency
|
28
32
|
name: rake
|
29
33
|
requirement: !ruby/object:Gem::Requirement
|
34
|
+
none: false
|
30
35
|
requirements:
|
31
|
-
- -
|
36
|
+
- - ! '>='
|
32
37
|
- !ruby/object:Gem::Version
|
33
38
|
version: '0'
|
34
39
|
type: :development
|
35
40
|
prerelease: false
|
36
41
|
version_requirements: !ruby/object:Gem::Requirement
|
42
|
+
none: false
|
37
43
|
requirements:
|
38
|
-
- -
|
44
|
+
- - ! '>='
|
39
45
|
- !ruby/object:Gem::Version
|
40
46
|
version: '0'
|
41
|
-
description:
|
47
|
+
description: Discombobulate for the greater good!
|
42
48
|
email:
|
43
49
|
- pawel.obrok@gmail.com
|
50
|
+
- wojtowicz.norbert@gmail.com
|
44
51
|
executables: []
|
45
52
|
extensions: []
|
46
53
|
extra_rdoc_files: []
|
47
54
|
files:
|
48
|
-
-
|
55
|
+
- .gitignore
|
49
56
|
- Gemfile
|
50
57
|
- LICENSE.txt
|
51
58
|
- README.md
|
52
59
|
- Rakefile
|
53
60
|
- discombobulator.gemspec
|
54
61
|
- lib/discombobulator.rb
|
55
|
-
- lib/discombobulator/
|
62
|
+
- lib/discombobulator/config.rb
|
63
|
+
- lib/discombobulator/dodge_attack.rb
|
64
|
+
- lib/discombobulator/super_call.rb
|
65
|
+
- lib/discombobulator/super_polymorphic.rb
|
66
|
+
- lib/discombobulator/swap_globals.rb
|
56
67
|
homepage: ''
|
57
68
|
licenses:
|
58
69
|
- MIT
|
59
|
-
metadata: {}
|
60
70
|
post_install_message:
|
61
71
|
rdoc_options: []
|
62
72
|
require_paths:
|
63
73
|
- lib
|
64
74
|
required_ruby_version: !ruby/object:Gem::Requirement
|
75
|
+
none: false
|
65
76
|
requirements:
|
66
|
-
- -
|
77
|
+
- - ! '>='
|
67
78
|
- !ruby/object:Gem::Version
|
68
79
|
version: '0'
|
69
80
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
70
82
|
requirements:
|
71
|
-
- -
|
83
|
+
- - ! '>='
|
72
84
|
- !ruby/object:Gem::Version
|
73
85
|
version: '0'
|
74
86
|
requirements: []
|
75
87
|
rubyforge_project:
|
76
|
-
rubygems_version:
|
88
|
+
rubygems_version: 1.8.23
|
77
89
|
signing_key:
|
78
|
-
specification_version:
|
79
|
-
summary:
|
90
|
+
specification_version: 3
|
91
|
+
summary: Discombobulate for the greater good!
|
80
92
|
test_files: []
|
81
93
|
has_rdoc:
|
checksums.yaml
DELETED
@@ -1,7 +0,0 @@
|
|
1
|
-
---
|
2
|
-
SHA1:
|
3
|
-
metadata.gz: 292f2727f036a4a2e0dad0f1b5e3ad7238cf1869
|
4
|
-
data.tar.gz: 4e1307be7319c248b4645203b53dd6438a710e3b
|
5
|
-
SHA512:
|
6
|
-
metadata.gz: 1ae63167877604bd681fad51ebae966f8f820663e91bbf4b7b7503b4040c79c087a3d78bf329ee64c088d393e4361dfbd8c631346558fad5590c6078de9c90de
|
7
|
-
data.tar.gz: 251f5940643fd1e0555a727723862182ee4eed89b8307c53c25fda75e244872207995a05431e9970b43f36d6c88ce450a48d1f68d2baae0fc22801d3b480d355
|