Skip to content

Commit

Permalink
Add ips alias_method vs alias
Browse files Browse the repository at this point in the history
  • Loading branch information
gonzedge committed Feb 22, 2018
1 parent 68f2132 commit 2ffd861
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions tasks/ips.rb
Expand Up @@ -23,6 +23,9 @@
compare_delegate_custom_and_direct
end

task :alias_vs_alias_method do
compare_alias_vs_alias_method
end
end

def compare
Expand Down Expand Up @@ -203,3 +206,50 @@ def compare_delegate_custom_and_direct
end
end

class TestAlias
def initialize hash
@hash = hash
end

def [] key
hash[key]
end

alias get []

private

attr_reader :hash
end

class TestAliasMethod
def initialize hash
@hash = hash
end

def [] key
hash[key]
end

alias_method :get, :[]

private

attr_reader :hash
end

def compare_alias_vs_alias_method
compare do |bm|
hash = { key: 'value' }

alias_test = TestAlias.new hash
bm.report 'alias' do
alias_test.get :key
end

alias_method_test = TestAliasMethod.new hash
bm.report 'alias_method' do
alias_method_test.get :key
end
end
end

0 comments on commit 2ffd861

Please sign in to comment.