Last active
December 10, 2015 18:48
-
-
Save asonas/4476547 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 | |
require "prime" | |
script = %w( | |
おちつけ.... | |
心を平静にして考えるんだ... | |
こんなときどうするか... | |
prime | |
落ち着くんだ | |
「素数」を数えて落ち着くんだ | |
) | |
script.each do |selif| | |
if selif == "prime" | |
Prime.take_while{ |n| n < 20 }.each do |n| | |
puts n | |
sleep 0.4 | |
end | |
else | |
p selif | |
end | |
sleep 1 | |
end |
kei-s
commented
Jan 7, 2013
👍
[
"おちつけ....",
"心を平静にして考えるんだ...",
"こんなときどうするか...",
Prime.take_while { |n| n < 20 },
"落ち着くんだ",
"「素数」を数えて落ち着くんだ"
].flatten.each { |selif|
p selif
sleep selif.instance_of?(String) ? 1 : 0.4
}
これだと最後の素数のあとの sleep が1.4秒でなく0.4秒になってしまうのだけれど、これは別に仕様ではないと判断して、このようにしました。
このgistのIDも素数です
irb(main):009:0> 4476547.prime?
=> true
リファクタリングと関係が無くて恐縮ですが。
zshを使っていて、焦って間違ったコマンドを打った時に、冷静になれるようにしました。
function command_not_found_handler() {
echo "\"こ...この$0コマンドは....『command not found』じゃあないか....\"" 1>&2
sleep 1
ruby prime.rb
#本来はこっちを返すけど、command not foundが2重表示され冗長でカッコ悪い感じ
#return 127
#最後のcommand not foundを消すために0で返す
return 0
}
この関数を".zshrc"に追記したり、"notfound.zsh"に書いてsource notfound.zsh
する事で使えますー。
天下のslコマンドと同じ匂いがします。
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment