Skip to content

Commit

Permalink
Add memoization for methods based on immutable state
Browse files Browse the repository at this point in the history
[Fix #9]
  • Loading branch information
dkubb committed Aug 11, 2014
1 parent db8afee commit 365f47c
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 2 deletions.
2 changes: 1 addition & 1 deletion config/flog.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
threshold: 15.0
threshold: 16.3
5 changes: 4 additions & 1 deletion lib/adamantium.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,10 @@ def self.included(descendant)
descendant.class_eval do
include Memoizable
extend ModuleMethods
extend ClassMethods if instance_of?(Class)
if instance_of?(Class)
extend ClassMethods
memoize(:hash, :inspect, :to_s)
end
end
end
private_class_method :included
Expand Down
13 changes: 13 additions & 0 deletions spec/unit/adamantium/hash_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# encoding: utf-8

require 'spec_helper'
require File.expand_path('../fixtures/classes', __FILE__)

describe Adamantium, '#hash' do
subject { object.hash }

let(:object) { described_class.new }
let(:described_class) { AdamantiumSpecs::Object }

it_behaves_like 'a hash method'
end
13 changes: 13 additions & 0 deletions spec/unit/adamantium/inspect_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# encoding: utf-8

require 'spec_helper'
require File.expand_path('../fixtures/classes', __FILE__)

describe Adamantium, '#inspect' do
subject { object.inspect }

let(:object) { described_class.new }
let(:described_class) { AdamantiumSpecs::Object }

it_behaves_like 'an idempotent method'
end
13 changes: 13 additions & 0 deletions spec/unit/adamantium/to_s_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# encoding: utf-8

require 'spec_helper'
require File.expand_path('../fixtures/classes', __FILE__)

describe Adamantium, '#to_s' do
subject { object.to_s }

let(:object) { described_class.new }
let(:described_class) { AdamantiumSpecs::Object }

it_behaves_like 'an idempotent method'
end

0 comments on commit 365f47c

Please sign in to comment.