Browse files

Rename Array#init to Array#butlast

  • Loading branch information...
1 parent 6b90c2d commit 900f7b5893afa5ce7b45aa78c6ac17ce7a004fac @bbatsov committed Aug 28, 2013
View
2 README.md
@@ -22,7 +22,7 @@ Or install it yourself as:
## Extensions
* [Array](http://rdoc.info/github/bbatsov/powerpack/Array)
- * [#init](http://rdoc.info/github/bbatsov/powerpack/Array#init-instance_method)
+ * [#butlast](http://rdoc.info/github/bbatsov/powerpack/Array#butlast-instance_method)
* [#tail](http://rdoc.info/github/bbatsov/powerpack/Array#tail-instance_method)
* [Enumerable](http://rdoc.info/github/bbatsov/powerpack/Enumerable)
* [#drop_last](http://rdoc.info/github/bbatsov/powerpack/Enumerable#drop_last-instance_method)
View
2 lib/powerpack/array.rb
@@ -1,2 +1,2 @@
-require_relative 'array/init'
+require_relative 'array/butlast'
require_relative 'array/tail'
View
15 lib/powerpack/array/butlast.rb
@@ -0,0 +1,15 @@
+unless Array.method_defined? :butlast
+ class Array
+ # Returns a new array that has all the elements of the current but the last.
+ #
+ # @return [Array] a new array without the last element or an empty array if this
+ # array is empty
+ #
+ # @example
+ # [1, 2, 3].butlast #=> [1, 2]
+ # [].butlast #=> []
+ def butlast
+ self[0...-1]
+ end
+ end
+end
View
15 lib/powerpack/array/init.rb
@@ -1,15 +0,0 @@
-unless Array.method_defined? :init
- class Array
- # Returns a new array that has all the elements of the current but the last.
- #
- # @return [Array] a new array without the last element or empty array if this
- # array is empty
- #
- # @example
- # [1, 2, 3].init #=> [1, 2]
- # [].init #=> []
- def init
- self[0...-1]
- end
- end
-end
View
6 spec/powerpack/array/init_spec.rb → spec/powerpack/array/butlast_spec.rb
@@ -1,11 +1,11 @@
require 'spec_helper'
-describe 'Array#init' do
+describe 'Array#butlast' do
it 'returns an array without the last element' do
- expect([1, 2, 3].init).to eq([1, 2])
+ expect([1, 2, 3].butlast).to eq([1, 2])
end
it 'returns [] for empty lists' do
- expect([].init).to be_empty
+ expect([].butlast).to be_empty
end
end

0 comments on commit 900f7b5

Please sign in to comment.