Skip to content

Instantly share code, notes, and snippets.

@asonas
Last active December 10, 2015 18:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save asonas/4476547 to your computer and use it in GitHub Desktop.
Save asonas/4476547 to your computer and use it in GitHub Desktop.
リファクタリングお願いします。
# 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
Copy link

kei-s commented Jan 7, 2013

Prime.take_while{|n| n<20}.each do |n|
  puts n  
  sleep 0.4  
end

@asonas
Copy link
Author

asonas commented Jan 7, 2013

👍

@june29
Copy link

june29 commented Jan 8, 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秒になってしまうのだけれど、これは別に仕様ではないと判断して、このようにしました。

@asonas
Copy link
Author

asonas commented Jan 8, 2013

このgistのIDも素数です

irb(main):009:0> 4476547.prime?
=> true

@FromAtom
Copy link

FromAtom commented Jan 8, 2013

リファクタリングと関係が無くて恐縮ですが。
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コマンドと同じ匂いがします。

@asonas
Copy link
Author

asonas commented Jan 9, 2013

惚れさせ835 「物凄い力」 すごい…これが 仲間たちの力か…! 俺の今までの 努力ってなんだったんだ…!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment