class Discombobulator::CosmicRays
Public Class Methods
call(meth, *args, &block)
click to toggle source
# File lib/discombobulator/cosmic_rays.rb, line 2 def self.call(meth, *args, &block) self.new.call(meth, *args, &block) end
Public Instance Methods
call(meth, *args, &block)
click to toggle source
# File lib/discombobulator/cosmic_rays.rb, line 6 def call(meth, *args, &block) if object = find_me_a_victim name = object.instance_variables.shuffle.find{ |var| is_a_number?(object, var) } cosmic_ray_flip_flop(object, name) end Discombobulator.new end
cosmic_ray_flip_flop(object, name)
click to toggle source
# File lib/discombobulator/cosmic_rays.rb, line 15 def cosmic_ray_flip_flop(object, name) value = object.instance_variable_get(name) new_value = Flipper.new(value).call if $DISCOMBOBULATOR_SAFETY_FEATURE == 42 p "Changing #{object.class} #{name} from #{value} to #{new_value}" else object.instance_variable_set(name, new_value) end end
find_me_a_victim()
click to toggle source
# File lib/discombobulator/cosmic_rays.rb, line 25 def find_me_a_victim ObjectSpace.each_object.to_a.shuffle.each do |obj| return obj if has_a_number?(obj) end nil end
has_a_number?(obj)
click to toggle source
# File lib/discombobulator/cosmic_rays.rb, line 32 def has_a_number?(obj) obj.instance_variables.any?{ |name| is_a_number?(obj, name) } end
is_a_number?(obj, name)
click to toggle source
# File lib/discombobulator/cosmic_rays.rb, line 36 def is_a_number?(obj, name) obj.instance_variable_get(name).kind_of?(Integer) end