fREWdiculous!
26 Dec
Exciting! It was apparently put up yesterday, on Christmas. What a cool gift right? I looked through the changed maintained my Mauricio and here are /my/ favorites.
New literal hash syntax [Ruby2]
.() and calling Procs without #call/#[] [EXPERIMENTAL]
You can now do:
Multiple splats allowed
1.9 allows multiple splat operators when calling a method:
Mandatory arguments after optional arguments allowed
Object#tap
Passes the object to the block and returns it (meant to be used for call chaining).
Module#attr is an alias of attr_reader
Use
to create a read/write accessor. (RCR#331)
Enumerable#cycle
Calls the given block for each element of the enumerable in a never-ending cycle:
Enumerable#group_by
Groups the values in the enumerable according to the value returned by the block:
Enumerable#drop
Without a block, returns an array with all but the first n elements from the enumeration. Otherwise drops elements while the block returns true (and returns all the elements after it returns a false value):
Enumerable#inject (#reduce) without a block
If no block is given, the first argument to #inject is the name of a two-argument method that will be called; the optional second argument is the initial value:
Enumerable#count
It could be defined in Ruby as
Therefore
Array#nitems
It is equivalent to selecting the elements that satisfy a condition and obtaining the size of the resulting array:
Block argument to Array#index, Array#rindex [Ruby2]
They can now take a block to make them work like #select.
Array#combination
yields all the combinations of length n of the elements in the array to the given block. If no block is passed, it returns an enumerator instead. The order of the combinations is unspecified.
Array#permutation
Array#pop, Array#shift
They can take an argument to specify how many objects to return:
Hash preserves order!
vs.
Numeric#upto, #downto, #times, #step
These methods return an enumerator if no block is given:
Range#cover?
compares value to the begin and end values of the range, returning true if it is comprised between them, honoring #exclude_end?.
Limit input in IO#gets, IO#readline, IO#readlines, IO#each_line, IO#lines, IO.foreach, IO.readlines, StringIO#gets, StringIO#readline, StringIO#each, StringIO#readlines
These methods accept an optional integer argument to specify the maximum amount of data to be read. The limit is specified either as the (optional) second argument, or by passing a single integer argument (i.e. the first argument is interpreted as the limit if it’s an integer, as a line separator otherwise).
IO#ungetc, StringIO#ungetc
Allows to push back an arbitrarily large character.
Seven predicate methods where added for the weekdays: