Skip to content

Instantly share code, notes, and snippets.

@rwz
rwz / throw-catch.rb
Created November 6, 2015 19:06
How ensure/return breaks throw/catch
def run_with_elapsed_time
time_at_start = Time.now
exception = nil
result = yield
rescue => e
exception = e
ensure
return [ result, exception, Time.now - time_at_start ]
end
my_string.scan(/[a-z\d]+/).each_with_object(Hash.new(0)){ |e, a| a[e] += 1 }
@rwz
rwz / p5n.md
Last active October 24, 2021 15:09
persona 5 negotiatons

Codes:

  • L: Likes
  • D: Dislikes
  • M: Meh.

Depending on the persona for successful negotiation you need either 2 Like answers or 1 Like + 1 Meh.


@rwz
rwz / wtf.rb
Last active April 26, 2017 19:00
dynamic method definition in ruby
class MyClass
def static_yield(*)
yield if block_given?
end
define_method :dynamic_yield do |*|
yield if block_given?
end
define_method :dynamic_yield_fix do |*, &block|