Skip to content

Commit

Permalink
rubocop -a
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewrudy committed Jun 20, 2017
1 parent 9d29d19 commit d0d7fb8
Show file tree
Hide file tree
Showing 8 changed files with 110 additions and 110 deletions.
11 changes: 6 additions & 5 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
# encoding: utf-8
require "bundler/gem_tasks"

require "rake/testtask"
require 'bundler/gem_tasks'

require 'rake/testtask'
Rake::TestTask.new do |t|
t.libs << "test"
t.test_files = FileList["test/**/*_test.rb"]
t.libs << 'test'
t.test_files = FileList['test/**/*_test.rb']
t.verbose = true
end

task :default => ["test"]
task default: ['test']
25 changes: 11 additions & 14 deletions lib/memoist.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# frozen_string_literal: true

require 'memoist/version'
require 'memoist/core_ext/singleton_class'

module Memoist

def self.extended(extender)
Memoist.memoist_eval(extender) do
unless singleton_class.method_defined?(:memoized_methods)
Expand All @@ -14,27 +14,27 @@ def self.memoized_methods
end
end

def self.memoized_ivar_for(method_name, identifier=nil)
def self.memoized_ivar_for(method_name, identifier = nil)
"@#{memoized_prefix(identifier)}_#{escape_punctuation(method_name)}"
end

def self.unmemoized_method_for(method_name, identifier=nil)
def self.unmemoized_method_for(method_name, identifier = nil)
"#{unmemoized_prefix(identifier)}_#{method_name}".to_sym
end

def self.memoized_prefix(identifier=nil)
def self.memoized_prefix(identifier = nil)
if identifier
"_memoized_#{identifier}"
else
"_memoized".freeze
'_memoized'.freeze
end
end

def self.unmemoized_prefix(identifier=nil)
def self.unmemoized_prefix(identifier = nil)
if identifier
"_unmemoized_#{identifier}"
else
"_unmemoized".freeze
'_unmemoized'.freeze
end
end

Expand Down Expand Up @@ -76,7 +76,7 @@ def unmemoize_all
end

def memoized_structs(names)
ref_obj = self.class.respond_to?(:class_eval) ? self.singleton_class : self
ref_obj = self.class.respond_to?(:class_eval) ? singleton_class : self
structs = ref_obj.all_memoized_structs
return structs if names.empty?

Expand Down Expand Up @@ -111,7 +111,7 @@ def all_memoized_structs
# an ancestor method.
ancestors.grep(Memoist).each do |ancestor|
ancestor.memoized_methods.each do |m|
structs << m unless structs.any? {|am| am.memoized_method == m.memoized_method }
structs << m unless structs.any? { |am| am.memoized_method == m.memoized_method }
end
end
structs
Expand All @@ -123,9 +123,7 @@ def clear_structs
end

def memoize(*method_names)
if method_names.last.is_a?(Hash)
identifier = method_names.pop[:identifier]
end
identifier = method_names.pop[:identifier] if method_names.last.is_a?(Hash)

method_names.each do |method_name|
unmemoized_method = Memoist.unmemoized_method_for(method_name, identifier)
Expand All @@ -141,7 +139,7 @@ def memoize(*method_names)
alias_method unmemoized_method, method_name

mm = MemoizedMethod.new(method_name, memoized_ivar, instance_method(method_name).arity)
self.memoized_methods << mm
memoized_methods << mm
if mm.arity == 0

# define a method like this;
Expand Down Expand Up @@ -238,5 +236,4 @@ def #{method_name}(*args)
# return a chainable method_name symbol if we can
method_names.length == 1 ? method_names.first : method_names
end

end
11 changes: 7 additions & 4 deletions lib/memoist/core_ext/singleton_class.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
# frozen_string_literal: true

module Kernel
# Returns the object's singleton class.
def singleton_class
class << self
self
unless respond_to?(:singleton_class)
def singleton_class
class << self
self
end
end
end unless respond_to?(:singleton_class) # exists in 1.9.2
end # exists in 1.9.2
end
3 changes: 2 additions & 1 deletion lib/memoist/version.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# frozen_string_literal: true

module Memoist
VERSION = "0.15.0"
VERSION = '0.15.0'.freeze
end
51 changes: 26 additions & 25 deletions memoist.gemspec
Original file line number Diff line number Diff line change
@@ -1,43 +1,44 @@
# coding: utf-8

lib = File.expand_path('../lib', __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'memoist/version'

AUTHORS = [
["Joshua Peek", "[email protected]"],
["Tarmo Tänav", "[email protected]"],
["Jeremy Kemper", "[email protected]"],
["Eugene Pimenov", "[email protected]"],
["Xavier Noria", "[email protected]"],
["Niels Ganser", "[email protected]"],
["Carl Lerche & Yehuda Katz", "[email protected]"],
["jeem", "[email protected]"],
["Jay Pignata", "[email protected]"],
["Damien Mathieu", "[email protected]"],
["José Valim", "[email protected]"],
["Matthew Rudy Jacobs", "[email protected]"],
]
['Joshua Peek', '[email protected]'],
['Tarmo Tänav', '[email protected]'],
['Jeremy Kemper', '[email protected]'],
['Eugene Pimenov', '[email protected]'],
['Xavier Noria', '[email protected]'],
['Niels Ganser', '[email protected]'],
['Carl Lerche & Yehuda Katz', '[email protected]'],
['jeem', '[email protected]'],
['Jay Pignata', '[email protected]'],
['Damien Mathieu', '[email protected]'],
['José Valim', '[email protected]'],
['Matthew Rudy Jacobs', '[email protected]']
].freeze

Gem::Specification.new do |spec|
spec.name = "memoist"
spec.name = 'memoist'
spec.version = Memoist::VERSION
spec.authors = AUTHORS.map{ |name, email| name }
spec.email = AUTHORS.map{ |name, email| email }
spec.summary = %q{memoize methods invocation}
spec.homepage = "https://github.com/matthewrudy/memoist"
spec.license = "MIT"
spec.authors = AUTHORS.map { |name, _email| name }
spec.email = AUTHORS.map { |_name, email| email }
spec.summary = 'memoize methods invocation'
spec.homepage = 'https://github.com/matthewrudy/memoist'
spec.license = 'MIT'

spec.files = `git ls-files -z`.split("\x0")
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
spec.require_paths = ["lib"]
spec.require_paths = ['lib']

spec.add_development_dependency "benchmark-ips"
spec.add_development_dependency "bundler"
spec.add_development_dependency 'benchmark-ips'
spec.add_development_dependency 'bundler'
if RUBY_VERSION < '1.9.3'
spec.add_development_dependency "rake", "~> 10.4"
spec.add_development_dependency 'rake', '~> 10.4'
else
spec.add_development_dependency "rake"
spec.add_development_dependency 'rake'
end
spec.add_development_dependency "minitest", "~> 5.10"
spec.add_development_dependency 'minitest', '~> 5.10'
end
8 changes: 4 additions & 4 deletions script/benchmark.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
$:.unshift File.expand_path(File.dirname(__FILE__)+"/../lib")
$LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/../lib')
require 'benchmark/ips'

require 'memoist'
Expand All @@ -7,7 +7,7 @@ class Benchy
extend Memoist

def arity_0
"Hello World"
'Hello World'
end
memoize :arity_0

Expand All @@ -22,7 +22,7 @@ def arity_1(name)
puts "Benchmarking: #{Memoist::VERSION}"

Benchmark.ips do |x|
x.report("arity 0 - memoized") do |times|
x.report('arity 0 - memoized') do |times|
times.times do
OBJECT.arity_0
end
Expand All @@ -34,7 +34,7 @@ def arity_1(name)
# end
# end

x.report("arity 1 - memoized") do |times|
x.report('arity 1 - memoized') do |times|
times.times do
OBJECT.arity_1(:World)
end
Expand Down
Loading

0 comments on commit d0d7fb8

Please sign in to comment.