This file contains hidden or 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
lambda{|*args| args}.call(1, 2) | |
#=> [1, 2] | |
# This is the splat operator used in the 'collecting mode'. | |
# The splat before the args ensured that all arguments were marshalled into an Array. | |
[1, 2, [3, 4]] | |
#=> [1, 2, [3, 4]] | |
[1, 2, *[3, 4]] | |
#=> [1, 2, 3, 4] | |
# This is the unmarshalling 'mode' of the splat operator. |
This file contains hidden or 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
[:a, :b, :c].map {|e| e.to_s } | |
#=> ['a', 'b', 'c'] # Invoke .to_s on each element and collect these in an array. | |
[:a, :b, :c].map(&:to_s) | |
#=> ['a', 'b', 'c'] # The same result obtained in a shorthand fashion. |
This file contains hidden or 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
{:a => 'alpha'}.to_a | |
#=> [[:a, "alpha"]] # Notice the nested array | |
Hash[:a => 'alpha'] | |
#=> {:a => 'alpha'} | |
Hash[[:a => 'alpha']] | |
#=> {} # Doesn't work with a nested array. | |
Hash[[[:a => 'alpha']]] |
This file contains hidden or 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
class Array | |
def flatten_hashes | |
Hash[*self.map(&:to_a).flatten] | |
end | |
end | |
[{:a => 'alpha'}, {:b => 'beta'}, {:c => 'charlie'}].flatten_hashes | |
#=> {:a => 'alpha', :b => 'beta', :c => 'charlie'} |
This file contains hidden or 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
git log HEAD^..HEAD --format="%an pushed change %h on %aD.%n%nWhat's in this change?%n%s%n" |
This file contains hidden or 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
#!/usr/bin/env sh | |
# Copy public key to authorized_keys of a remote machine | |
if [ -z $1 ];then | |
echo "Usage" | |
echo "ssh-copy-id hostname /path/to/public/key" | |
exit | |
fi | |
if [ -z $2 ]; then | |
KEYCODE=`ssh-add -L` |
NewerOlder