class SelfDefense
file: self-defense.rb
Public Class Methods
new() { |self| ... }
click to toggle source
Calls superclass method
# File lib/self-defense.rb, line 9 def initialize(&block) super() @unit = {s: proc{|x| x}, m: proc{|x| x*60}, h: proc{|x| x*60*60}} yield(self) end
new()
click to toggle source
Calls superclass method
# File lib/self-defense.rb, line 15 def self.new super() @@hits << Time.now end
Public Instance Methods
rapid?(recovery_period=0.8)
click to toggle source
# File lib/self-defense.rb, line 20 def rapid?(recovery_period=0.8) (Time.now - @@hits.last) > recovery_period end
sustained?(h={})
click to toggle source
# File lib/self-defense.rb, line 24 def sustained?(h={}) duration = @unit[h[:duration].slice!(-1).to_sym].call(h[:duration]) @@hits.select {|x| @@hits.last - x <= duration.to_i}.length < h[:hit_limit] + 1 end