Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
typo        2012-02-22  kchinda@aiming-inc.com       (a.k.a. @ckazu)
about me• @ckazu•    •                G        • Rails        • Rails   + JS• Rails, Ruby                       17
Shinjuku.rb #01
http://www.slideshare.net/ckazu/rails5
typo
typo
• typo
typo
•    • User.count   → User.coutn
module TypoFixer  def self.included(base)    base.class_eval do      alias_method :method_missing_without_fix_typo, :metho...
require typo_fixerclass Sample  include TypoFixer  def some_method    some value  endendsample = Sample.newp sample.sme_mo...
require typo_fixerclass Object  include TypoFixerendp [1, 2, 3].shaflfe.joni #=> "213"                        https://gist...
•    • User.count   → User.caunt
module TypoFixer  def self.included(base)    base.class_eval do      alias_method :method_missing_without_fix_typo, :metho...
require typo_fixerclass Object  include TypoFixerendp "some string".revarse #=> "gnirts emos"                        https...
•    • array.flatten   → array.flaten
•
•    • car.control   → car.controll
•
•    • User.fin_dvy_id(di)
•
•   method   typo
•
http://suburi.herokuapp.com/
typo の傾向と対策
typo の傾向と対策
typo の傾向と対策
typo の傾向と対策
typo の傾向と対策
typo の傾向と対策
typo の傾向と対策
typo の傾向と対策
typo の傾向と対策
typo の傾向と対策
Upcoming SlideShare
Loading in …5
×

typo の傾向と対策

2,387 views

Published on

shinjuku.rb #02 LT

typo の傾向と対策

  1. 1. typo 2012-02-22 kchinda@aiming-inc.com (a.k.a. @ckazu)
  2. 2. about me• @ckazu• • G • Rails • Rails + JS• Rails, Ruby 17
  3. 3. Shinjuku.rb #01
  4. 4. http://www.slideshare.net/ckazu/rails5
  5. 5. typo
  6. 6. typo
  7. 7. • typo
  8. 8. typo
  9. 9. • • User.count → User.coutn
  10. 10. module 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
  11. 11. require typo_fixerclass Sample  include TypoFixer  def some_method    some value  endendsample = Sample.newp sample.sme_motoehd #=> some valuep sample.sme_motoehd.reveres #=> error! https://gist.github.com/1870273
  12. 12. require typo_fixerclass Object  include TypoFixerendp [1, 2, 3].shaflfe.joni #=> "213" https://gist.github.com/1870273
  13. 13. • • User.count → User.caunt
  14. 14. module 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
  15. 15. require typo_fixerclass Object  include TypoFixerendp "some string".revarse #=> "gnirts emos" https://gist.github.com/1870273
  16. 16. • • array.flatten → array.flaten
  17. 17.
  18. 18. • • car.control → car.controll
  19. 19.
  20. 20. • • User.fin_dvy_id(di)
  21. 21.
  22. 22. • method typo
  23. 23.
  24. 24. http://suburi.herokuapp.com/

×