Module: RubyIs
- Defined in:
- lib/ruby_is.rb,
lib/ruby_is/version.rb
Constant Summary collapse
- VERSION =
"1.0.1"
Class Method Summary collapse
Class Method Details
.block(&b) ⇒ Object
14 |
# File 'lib/ruby_is.rb', line 14 def block(&b); b; end |
.cache ⇒ Object
16 |
# File 'lib/ruby_is.rb', line 16 def cache; @@cache ||= {}; end |
.proc_or_block(args, block) ⇒ Object
5 6 7 8 9 10 11 12 |
# 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) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/ruby_is.rb', line 18 def with_memo(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 |