memoyze 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: dace847891950f3437c0975df9520c54d6a162f7
4
+ data.tar.gz: b31b1be6e931c02b186a2e32cbd1c6f61b439a8f
5
+ SHA512:
6
+ metadata.gz: d948e3ed18c300211ce15094824983a7f1e021e5731c6ad9b27b37e5fd888cf2513c1200f26dda4f039befe01f6d3fa5d6699f52544003a9de1d055581fc20ec
7
+ data.tar.gz: 8aa279b12db8b0ecde41a5cb6a76f5666211282a9ee5c29620ff21d4759710d94868d1620cdd1b37e1a97f3580a5ff9d374c3f8f7261c61aea1ae5bdc0e6871d
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+
5
+ group :test do
6
+ gem 'rspec'
7
+ end
@@ -0,0 +1,21 @@
1
+ # MIT LICENSE
2
+
3
+ Copyright (c) 2019 Sven Fuchs <me@svenfuchs.com>
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,30 @@
1
+ # Memoize [![Build Status](https://travis-ci.org/svenfuchs/memoize.svg?branch=master)](https://travis-ci.org/svenfuchs/memoize)
2
+
3
+ Simplistic memoization using instance variables.
4
+
5
+ ## Installation
6
+
7
+ ```
8
+ gem install
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ```ruby
14
+ require 'memoize'
15
+
16
+ class Obj
17
+ include Memoize
18
+
19
+ # on a separate line, after the method definition
20
+ def foo
21
+ # expensive operation
22
+ end
23
+ memoize :foo
24
+
25
+ # on one line, before the method definition
26
+ memoize def bar
27
+ # expensive operation
28
+ end
29
+ end
30
+ ```
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+ module Memoize
3
+ class ArgsError < StandardError; end
4
+
5
+ module ClassMethods
6
+ def memoize(name)
7
+ ivar = :"@#{name.to_s.sub('?', '_predicate')}"
8
+ prepend Module.new {
9
+ define_method(name) do |*args|
10
+ raise ArgsError.new('cannot pass arguments to memoized method %p' % name) unless args.empty?
11
+ return instance_variable_get(ivar) if instance_variable_defined?(ivar)
12
+ instance_variable_set(ivar, super())
13
+ end
14
+ }
15
+ end
16
+ end
17
+
18
+ def self.included(base)
19
+ base.extend(ClassMethods)
20
+ end
21
+ end
@@ -0,0 +1,3 @@
1
+ module Memoize
2
+ VERSION = '0.0.1'
3
+ end
metadata ADDED
@@ -0,0 +1,49 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: memoyze
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Sven Fuchs
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-04-22 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: "[description]"
14
+ email:
15
+ - me@svenfuchs.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - Gemfile
21
+ - LICENSE.md
22
+ - README.md
23
+ - lib/memoize.rb
24
+ - lib/memoize/version.rb
25
+ homepage: https://github.com/svenfuchs/memoize
26
+ licenses:
27
+ - MIT
28
+ metadata: {}
29
+ post_install_message:
30
+ rdoc_options: []
31
+ require_paths:
32
+ - lib
33
+ required_ruby_version: !ruby/object:Gem::Requirement
34
+ requirements:
35
+ - - ">="
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ required_rubygems_version: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ version: '0'
43
+ requirements: []
44
+ rubyforge_project:
45
+ rubygems_version: 2.6.13
46
+ signing_key:
47
+ specification_version: 4
48
+ summary: "[summary]"
49
+ test_files: []