Skip to content

Instantly share code, notes, and snippets.

@duckinator
Created May 25, 2016 08:06
Show Gist options
  • Save duckinator/ff52a1eca8b292e2d1d102b94c5a6a2e to your computer and use it in GitHub Desktop.
Save duckinator/ff52a1eca8b292e2d1d102b94c5a6a2e to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
$: << '../net-socket/lib'
$: << './lib'
require 'from'
from('net/socket').import(:TCP)
p Object.constants.grep /VERSION/
p Net::Socket.constants
__END__
# @param start_time [Time]
# @param time_limit [Numeric] The time limit in milliseconds.
def check_iteration_start_time(start_time, time_limit = 500)
start_time < (Time.now - time_limit)
end
def module_with_each?(mod)
mod.is_a?(Module) && mod.instance_methods(false).include?(:each)
end
def limit_enumerable_methods!(mod)
mod.module_exec do
alias_method :unlimited_enumerable_each
def each(*args, &block)
Thread.current[:iteration_start_time] = Time.now
super(*args) do
raise if Thread.current[:iterations] > 10_000
yield
end
end
end
end
Object.constants
.map(&Object.method(:const_get))
.select(&method(:module_with_each?))
.map(&method(:limit_enumerable_methods!))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment