34
typo 傾向対策 2012-02-22 [email protected] (a.k.a. @ckazu)

typo の傾向と対策

Embed Size (px)

DESCRIPTION

shinjuku.rb #02 LT

Citation preview

Page 2: typo の傾向と対策

about me

•@ckazu•

•東京開発G•Rails によるサイト開発•Rails + JS によるブラウザゲーム開発

•Rails, Ruby を業務で使い始めて17ヶ月

Page 3: typo の傾向と対策

Shinjuku.rb #01

Page 5: typo の傾向と対策

みなさん

Page 6: typo の傾向と対策

typo してますか

Page 7: typo の傾向と対策

typo をなくしましょう

Page 8: typo の傾向と対策

今日の内容

•typo いかに克服するか

Page 9: typo の傾向と対策

typo の傾向と対策

Page 10: typo の傾向と対策

傾向その1

•入れ替わり•User.count → User.coutn

Page 11: typo の傾向と対策

解決策1module TypoFixer  def self.included(base)    base.class_eval do      alias_method :method_missing_without_fix_typo, :method_missing      alias_method :method_missing, :method_missing_with_fix_typo    end  end

  def method_missing_with_fix_typo(name, *args)    if name && method = find_method(name)      $stderr.puts "WARNING: execute `#{name}` as `#{method}` for #{self}"      send(method, *args)    else      method_missing_without_fix_typo(name, *args)    end  end

  private  def find_method name    name.to_s.split(//).permutation.each do |candidate|      _candidate = candidate.join      return _candidate if respond_to?(_candidate, true)    end    nil  endend https://gist.github.com/1870273

組み合わせを全チェック

Page 12: typo の傾向と対策

解決策1require 'typo_fixer'

class Sample  include TypoFixer

  def some_method    'some value'  endend

sample = Sample.newp sample.sme_motoehd #=> 'some value'p sample.sme_motoehd.reveres #=> error!

https://gist.github.com/1870273

Page 13: typo の傾向と対策

解決策1require 'typo_fixer'

class Object  include TypoFixerend

p [1, 2, 3].shaflfe.joni #=> "213"

https://gist.github.com/1870273

こわいですね.

Page 14: typo の傾向と対策

傾向その2

•一文字だけ違う•User.count → User.caunt

Page 15: typo の傾向と対策

解決策2module TypoFixer  def self.included(base)    base.class_eval do      alias_method :method_missing_without_fix_typo, :method_missing      alias_method :method_missing, :method_missing_with_fix_typo    end  end

  def method_missing_with_fix_typo(name, *args)    if method = find_method(name)      $stdout.print "WARNING: execute `#{name}` as `#{method}`? [Y/n] "      return send(method, *args) if ($stdin.getc == 'Y')    end

    method_missing_without_fix_typo(name, *args)  end

  private  def find_method name    self.class.instance_methods.each do |method|      next unless method.size == name.size if(method.to_s.split(//) - name.to_s.split(//)).size == 1       return method end    end  endend https://gist.github.com/1883331

とりあえずそれっぽいのを返す

配列の方が良いですね

Page 16: typo の傾向と対策

解決策2require 'typo_fixer'

class Object  include TypoFixerend

p "some string".revarse #=> "gnirts emos"

https://gist.github.com/1870273

Page 17: typo の傾向と対策

傾向その3

•少ない•array.flatten → array.flaten

Page 18: typo の傾向と対策

解決策3

•配列にして比較したときにひとつだけ違うので,解決策2とほぼ同じ

Page 19: typo の傾向と対策

傾向その4

•多い•car.control → car.controll

Page 20: typo の傾向と対策

解決策4

•配列にして比較したときにひとつだけ違うので,解決策2とほぼ同じ

Page 21: typo の傾向と対策

傾向その5

•複合型•User.fin_dvy_id(di)

Page 22: typo の傾向と対策

解決策5

•ここまで気にしていられない

Page 23: typo の傾向と対策

解決策?

•定義されている method と typo との単語間の距離(類似度)を算出して候補を提案する

Page 24: typo の傾向と対策

誰か作ってください

Page 25: typo の傾向と対策

番外編

Page 26: typo の傾向と対策

番外編

•体育会系解決策

Page 27: typo の傾向と対策

素振り

Page 28: typo の傾向と対策

タイピングも準備運動大事

Page 29: typo の傾向と対策

基礎練大事

Page 30: typo の傾向と対策

朝練しましょう

Page 31: typo の傾向と対策

就業時には居残り特訓しましょう

Page 32: typo の傾向と対策

無性にタイピングしまくりたくなることありませんか?

Page 33: typo の傾向と対策

プログラマのための素振りサイト

http://suburi.herokuapp.com/

超プロトタイプ版!

バグてんこ盛り!

Page 34: typo の傾向と対策