Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
memery (1.2.0)
memery (1.3.0)

GEM
remote: https://rubygems.org/
Expand Down
1 change: 1 addition & 0 deletions lib/memery.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ module ClassMethods
def memoize(method_name, condition: nil, ttl: nil)
prepend_memery_module!
define_memoized_method!(method_name, condition: condition, ttl: ttl)
method_name
end

def memoized?(method_name)
Expand Down
2 changes: 1 addition & 1 deletion lib/memery/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module Memery
VERSION = "1.2.0"
VERSION = "1.3.0"
end
18 changes: 18 additions & 0 deletions spec/memery_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,16 @@ class F
def m; end
end

class G
include Memery

def self.macro(name)
define_method(:macro_received) { name }
end

macro memoize def g; end
end
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. It can be tested like expect(G.memoize(:g)).to eq :g
  2. Also via class-reader and @memoize_result = memoize def d, I guess.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call, but i want to avoid G modifications in specs.

I.e. i could use F, but when i call memoize on F, it will have F#m memoized

Copy link
Contributor

@AlexWayfer AlexWayfer Jan 31, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but i want to avoid G modifications in specs.

define_method is modification, but OK.

I.e. i could use F, but when i call memoize on F, it will have F#m memoized

That's why stabbing consts is better then global definition.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

define_method is modification, but OK.

Is is called before suite

That's why stabbing consts is better then global definition.

This PR does not point specs refactoring, but i agree with that a lot

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR does not point specs refactoring

I know, I know, just side notes.


RSpec.describe Memery do
subject(:a) { A.new }

Expand Down Expand Up @@ -190,6 +200,14 @@ def m; end
end
end

context "Chaining macros" do
subject(:g) { G.new }

specify do
expect(g.macro_received).to eq :g
end
end

context "inherited class" do
subject(:b) { B.new }

Expand Down