module RubyIs
Constants
- VERSION
Public Class Methods
block(&b)
click to toggle source
# File lib/ruby_is.rb, line 14 def block(&b); b; end
cache()
click to toggle source
# File lib/ruby_is.rb, line 16 def cache; @@cache ||= {}; end
eval_memoized(f, args, proc)
click to toggle source
# File lib/ruby_is.rb, line 18 def eval_memoized(f, args, proc) cache = RubyIs.cache cache_key = [f, args, proc] if cache.has_key?(cache_key) cache[cache_key] else cache[cache_key] = f.call(*args, &proc) end end
eval_time_cached(f, caching_time, args, proc)
click to toggle source
# File lib/ruby_is.rb, line 28 def eval_time_cached(f, caching_time, args, proc) cache = RubyIs.cache cache_key = [f, args, proc] if cache.has_key?(cache_key) last_call_time, value = cache[cache_key] return value if (Time.now - last_call_time) < caching_time end value = f.call(*args, &proc) cache[cache_key] = [Time.now, value] value end
proc_or_block(args, block)
click to toggle source
# File lib/ruby_is.rb, line 5 def proc_or_block(args, block) case when args.empty? && block then block when (args.count == 1) && block.nil? then args.first else raise "Incorrect syntax for `is` statement" end end
with_memo(f, caching_time=nil)
click to toggle source
# File lib/ruby_is.rb, line 40 def with_memo(f, caching_time=nil) ->(*args, &proc){ if caching_time RubyIs.eval_time_cached(f, caching_time, args, proc) else RubyIs.eval_memoized(f, args, proc) end } end