-
-
Save alexch/6151497 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# encoding: utf-8 | |
module Kernel | |
alias :λ :lambda | |
end | |
class Hash | |
alias :+ :merge | |
alias :<< :merge! | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# encoding: utf-8 | |
require './aliases.rb' | |
describe 'cool aliases' do | |
describe 'lambda' do | |
it 'works with a regular call' do | |
p = lambda do | |
true | |
end | |
p.call.should == true | |
end | |
it 'works with an aliased call' do | |
p = λ do # unicode 03BB | |
true | |
end | |
p.call.should == true | |
end | |
end | |
describe 'hash methods' do | |
describe '+' do | |
it 'concatenates two arrays' do | |
([1] + [2]).should == [1,2] | |
end | |
it 'concatenates two hashes, aliasing merge' do | |
({a: 1} + {b: 2}).should == {a: 1, b: 2} | |
end | |
it 'makes a new object' do | |
a = {a: 1} | |
b = {b: 2} | |
(a + b).should == {a: 1, b: 2} | |
(a + b).object_id.should_not == a.object_id | |
end | |
end | |
describe '<<' do | |
it 'smooshes an item into an array' do | |
([1] << 2).should == [1,2] | |
end | |
it 'smooshes one hash into another, aliasing merge!' do | |
({a: 1} << {b: 2}).should == {a: 1, b: 2} | |
end | |
it 'mutates the original left-side object' do | |
a = {a: 1} | |
b = {b: 2} | |
(a << b).should == {a: 1, b: 2} | |
(a << b).object_id.should == a.object_id | |
end | |
it 'overwrites the left side with the right side' do | |
({a: 1} << {a: 2}).should == {a: 2} | |
end | |
end | |
end | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
todo:
π = Math::PI