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
for cmd in $(ruby -e 'print "irb".split(//).permutation(3).map(&:join).join(" ")') | |
do | |
alias $cmd="pry" | |
done |
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
#!/usr/bin/env ruby | |
# coding: utf-8 | |
require "forwardable" | |
require "csv" | |
require "MeCab" | |
class Mecab | |
def self.wakati |
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
#!/usr/bin/env ruby | |
# coding: utf-8 | |
class Hoge | |
FUGA = "fuga" | |
end | |
hash = {hoge: Hoge} | |
p hash[:hoge]::FUGA #=> "fuga" |
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
#!/usr/bin/env ruby | |
# coding: utf-8 | |
hash = [ | |
{hoge: {fuga: 3}}, | |
{hoge: {homu: 5}}, | |
{fuga: {hoge: 4}}, | |
{fuga: {pero: 6}} | |
] | |
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
#!/usr/bin/env ruby | |
# coding: utf-8 | |
require "date" | |
def default_time(now=DateTime.now) | |
@default_time ||= now | |
end | |
module ShowDefaultTime |
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
#!/usr/bin/env ruby | |
# coding: utf-8 | |
require "csv" | |
rows = [ | |
[nil, "ほげ"], | |
["", "ほげ"] | |
] |
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
#!/usr/bin/env ruby | |
# coding: utf-8 | |
require 'pp' | |
require 'date' | |
def each_by_time(a, b) | |
min_count = ((b - a) * 24*60).to_i + 1 | |
min_count.times.map{|t| |
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
#!/usr/bin/env ruby | |
# coding: utf-8 | |
flag = true | |
array = [1,2,3] | |
# array.include?(3) だと動く | |
if flag && array.include? 3 | |
p 'ok' | |
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
#!/usr/bin/env ruby | |
# coding: utf-8 | |
def levenshtein(a, b) | |
(0..a.size).inject([[*0..b.size+1]]){|d, i| | |
d << (0..b.size).inject([i+1]){|_d, j| | |
_d << [ | |
d[i][j+1] + 1, | |
_d[j] + 1, | |
d[i][j] + (a[i]==b[j] ?0:1) |
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
"た゛くてんか゛ふ゛んりされてるもし゛".gsub("\u309B", "\u3099").gsub("\u309C", "\u309A").encode("UTF-8", "UTF-8-MAC") | |
# => "だくてんがぶんりされてるもじ" |