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
# rake a:b[xx,yy] | |
desc "description place" | |
namespace :a do | |
task :b, :x, :y do |t, args| | |
args[:x] | |
args[:y] | |
end | |
end | |
# rake c | |
task :c do |
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
def do_each(hash) | |
result = {} | |
hash.each { |key, value| result[key] = do_something(value) } | |
result | |
end | |
def do_inject(hash) | |
hash.inject({}) { |result, pair| result[pair.first] = do_something(pair.last); result } | |
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
def do_each(hash) | |
result = {} | |
hash.each { |key, value| result[key] = do_something(value) } | |
result | |
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
def do_inject(hash) | |
hash.inject({}) { |result, pair| result[pair.first] = do_something(pair.last); result } | |
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
def do_tap(hash) | |
{}.tap do |result| | |
hash.each { |key, value| result[key] = do_something(value) } | |
end | |
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
def do_map(hash) | |
Hash[hash.map { |key, value| [key, do_something(value)] }] | |
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
$ ruby q.rb | |
1 true | |
2 false | |
3 true | |
4 false | |
5 A | |
Run options: --seed 65268 | |
# Running tests: |
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
sum = ->x,y,z { x + y + z }.curry | |
puts sum[2][3][4] | |
=> 9 |
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
(defn pi | |
([] (pi 0)) | |
([x] (println x) #(pi (+ x 1)))) | |
; result | |
=> (((((((pi))))))) | |
0 | |
1 | |
2 | |
3 |
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
prime = -> a=[false, false], z=1 do | |
n = a.size + 1 | |
b = a + [true] | |
(2..Math.sqrt(a.size)).each do |i| | |
if b[i] | |
x = 0 | |
while (y = i**2+x*i) < n | |
b[y] = false | |
x += 1 | |
end |
OlderNewer