lib/mem.rb in mem-0.1.5 vs lib/mem.rb in mem-0.2.0
- old
+ new
@@ -1,7 +1,9 @@
-require "mem/version"
+# frozen_string_literal: true
+require 'mem/version'
+
module Mem
def self.included(base)
base.extend(ClassMethods)
end
@@ -26,14 +28,13 @@
end
module ClassMethods
def memoize(method_name)
original_visibility =
- case
- when protected_instance_methods.include?(method_name)
+ if protected_instance_methods.include?(method_name)
:protected
- when private_instance_methods.include?(method_name)
+ elsif private_instance_methods.include?(method_name)
:private
else
:public
end
@@ -52,14 +53,14 @@
define_method("unmemoize_#{method_name}") do
unmemoize(method_name)
end
send(original_visibility, "unmemoize_#{method_name}")
- if original_visibility != :private
- define_method("#{method_name}=") do |value|
- memoize(method_name, value)
- end
- send(original_visibility, "#{method_name}=")
+ return unless original_visibility != :private
+
+ define_method("#{method_name}=") do |value|
+ memoize(method_name, value)
end
+ send(original_visibility, "#{method_name}=")
end
end
end