discombobulator 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +6 -0
- data/discombobulator.gemspec +1 -1
- data/lib/discombobulator.rb +1 -0
- data/lib/discombobulator/cosmic_rays.rb +90 -0
- data/lib/discombobulator/super_polymorphic.rb +1 -0
- metadata +3 -2
data/README.md
CHANGED
data/discombobulator.gemspec
CHANGED
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
4
|
|
5
5
|
Gem::Specification.new do |spec|
|
6
6
|
spec.name = "discombobulator"
|
7
|
-
spec.version = "0.1.
|
7
|
+
spec.version = "0.1.2"
|
8
8
|
spec.authors = ["Paweł Obrok", "Norbert Wojtowicz"]
|
9
9
|
spec.email = ["pawel.obrok@gmail.com", "wojtowicz.norbert@gmail.com"]
|
10
10
|
spec.summary = "Discombobulate for the greater good!"
|
data/lib/discombobulator.rb
CHANGED
@@ -0,0 +1,90 @@
|
|
1
|
+
class Discombobulator::CosmicRays
|
2
|
+
def self.call(meth, *args, &block)
|
3
|
+
self.new.call(meth, *args, &block)
|
4
|
+
end
|
5
|
+
|
6
|
+
def call(meth, *args, &block)
|
7
|
+
if object = find_me_a_victim
|
8
|
+
name = object.instance_variables.shuffle.find{ |var| is_a_number?(object, var) }
|
9
|
+
cosmic_ray_flip_flop(object, name)
|
10
|
+
end
|
11
|
+
|
12
|
+
Discombobulator.new
|
13
|
+
end
|
14
|
+
|
15
|
+
def cosmic_ray_flip_flop(object, name)
|
16
|
+
value = object.instance_variable_get(name)
|
17
|
+
new_value = Flipper.new(value).call
|
18
|
+
if $DISCOMBOBULATOR_SAFETY_FEATURE == 42
|
19
|
+
p "Changing #{object.class} #{name} from #{value} to #{new_value}"
|
20
|
+
else
|
21
|
+
object.instance_variable_set(name, new_value)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def find_me_a_victim
|
26
|
+
ObjectSpace.each_object.to_a.shuffle.each do |obj|
|
27
|
+
return obj if has_a_number?(obj)
|
28
|
+
end
|
29
|
+
nil
|
30
|
+
end
|
31
|
+
|
32
|
+
def has_a_number?(obj)
|
33
|
+
obj.instance_variables.any?{ |name| is_a_number?(obj, name) }
|
34
|
+
end
|
35
|
+
|
36
|
+
def is_a_number?(obj, name)
|
37
|
+
obj.instance_variable_get(name).kind_of?(Integer)
|
38
|
+
end
|
39
|
+
|
40
|
+
class Flipper
|
41
|
+
def initialize(value)
|
42
|
+
@value = value
|
43
|
+
end
|
44
|
+
|
45
|
+
def call
|
46
|
+
method = [ :evil_flip, :complement, :cosmic_storm, :rescue_what_you_can, :trust_no_one ].shuffle.first
|
47
|
+
send(method)
|
48
|
+
end
|
49
|
+
|
50
|
+
private
|
51
|
+
attr_reader :value
|
52
|
+
|
53
|
+
def evil_flip
|
54
|
+
debug 'Evil flip'
|
55
|
+
value ^ 1
|
56
|
+
end
|
57
|
+
|
58
|
+
def complement
|
59
|
+
debug 'Complement'
|
60
|
+
~value
|
61
|
+
end
|
62
|
+
|
63
|
+
def cosmic_storm
|
64
|
+
debug 'Cosmic storm'
|
65
|
+
rand(max_integer)
|
66
|
+
end
|
67
|
+
|
68
|
+
def rescue_what_you_can
|
69
|
+
debug 'Rescue what you can'
|
70
|
+
value & rand(max_integer)
|
71
|
+
end
|
72
|
+
|
73
|
+
def trust_no_one
|
74
|
+
debug 'Trust no one'
|
75
|
+
value ^ rand(max_integer)
|
76
|
+
end
|
77
|
+
|
78
|
+
def max_integer
|
79
|
+
bytes = [42].pack('i').size
|
80
|
+
bits = bytes * 16
|
81
|
+
2 ** (bits - 2) - 1
|
82
|
+
end
|
83
|
+
|
84
|
+
def debug(msg)
|
85
|
+
p msg if $DISCOMBOBULATOR_SAFETY_FEATURE == 42
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
Discombobulator::Config.instance.add_plugin(Discombobulator::CosmicRays)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: discombobulator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2014-03-
|
13
|
+
date: 2014-03-24 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: bundler
|
@@ -60,6 +60,7 @@ files:
|
|
60
60
|
- discombobulator.gemspec
|
61
61
|
- lib/discombobulator.rb
|
62
62
|
- lib/discombobulator/config.rb
|
63
|
+
- lib/discombobulator/cosmic_rays.rb
|
63
64
|
- lib/discombobulator/dodge_attack.rb
|
64
65
|
- lib/discombobulator/super_call.rb
|
65
66
|
- lib/discombobulator/super_polymorphic.rb
|