SlideShare ist ein Scribd-Unternehmen logo
1 von 34
Downloaden Sie, um offline zu lesen
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, :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
  end
end
                                          https://gist.github.com/1870273
require 'typo_fixer'

class Sample
  include TypoFixer

  def some_method
    'some value'
  end
end

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

                        https://gist.github.com/1870273
require 'typo_fixer'

class Object
  include TypoFixer
end

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




                        https://gist.github.com/1870273
•

    • User.count   → User.caunt
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
  end
end                                      https://gist.github.com/1883331
require 'typo_fixer'

class Object
  include TypoFixer
end

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




                        https://gist.github.com/1870273
•

    • array.flatten   → array.flaten
•
•

    • car.control   → car.controll
•
•

    • User.fin_dvy_id(di)
•
•   method   typo
•
http://suburi.herokuapp.com/
typo の傾向と対策

Weitere ähnliche Inhalte

Ähnlich wie typo の傾向と対策

Presentation of the new OpenERP API. Raphael Collet, OpenERP
Presentation of the new OpenERP API. Raphael Collet, OpenERPPresentation of the new OpenERP API. Raphael Collet, OpenERP
Presentation of the new OpenERP API. Raphael Collet, OpenERP
Odoo
 
Metaprogramovanie #1
Metaprogramovanie #1Metaprogramovanie #1
Metaprogramovanie #1
Jano Suchal
 
Active Support Core Extension (2)
Active Support Core Extension (2)Active Support Core Extension (2)
Active Support Core Extension (2)
RORLAB
 
Desarrollando aplicaciones web en minutos
Desarrollando aplicaciones web en minutosDesarrollando aplicaciones web en minutos
Desarrollando aplicaciones web en minutos
Edgar Suarez
 
Metaprogramming 101
Metaprogramming 101Metaprogramming 101
Metaprogramming 101
Nando Vieira
 
ISUCONアプリを Pythonで書いてみた
ISUCONアプリを Pythonで書いてみたISUCONアプリを Pythonで書いてみた
ISUCONアプリを Pythonで書いてみた
memememomo
 
Functional programming using underscorejs
Functional programming using underscorejsFunctional programming using underscorejs
Functional programming using underscorejs
偉格 高
 
Groovy vs Boilerplate and Ceremony Code
Groovy vs Boilerplate and Ceremony CodeGroovy vs Boilerplate and Ceremony Code
Groovy vs Boilerplate and Ceremony Code
stasimus
 
Be RESTful (Symfony Camp 2008)
Be RESTful (Symfony Camp 2008)Be RESTful (Symfony Camp 2008)
Be RESTful (Symfony Camp 2008)
Fabien Potencier
 

Ähnlich wie typo の傾向と対策 (20)

Object.__class__.__dict__ - python object model and friends - with examples
Object.__class__.__dict__ - python object model and friends - with examplesObject.__class__.__dict__ - python object model and friends - with examples
Object.__class__.__dict__ - python object model and friends - with examples
 
Designing Ruby APIs
Designing Ruby APIsDesigning Ruby APIs
Designing Ruby APIs
 
Presentation of the new OpenERP API. Raphael Collet, OpenERP
Presentation of the new OpenERP API. Raphael Collet, OpenERPPresentation of the new OpenERP API. Raphael Collet, OpenERP
Presentation of the new OpenERP API. Raphael Collet, OpenERP
 
Dsl
DslDsl
Dsl
 
Intermediate SQL with Ecto - LoneStar ElixirConf 2018
Intermediate SQL with Ecto - LoneStar ElixirConf 2018Intermediate SQL with Ecto - LoneStar ElixirConf 2018
Intermediate SQL with Ecto - LoneStar ElixirConf 2018
 
Django Good Practices
Django Good PracticesDjango Good Practices
Django Good Practices
 
Metaprogramovanie #1
Metaprogramovanie #1Metaprogramovanie #1
Metaprogramovanie #1
 
Active Support Core Extension (2)
Active Support Core Extension (2)Active Support Core Extension (2)
Active Support Core Extension (2)
 
Creating Domain Specific Languages in Python
Creating Domain Specific Languages in PythonCreating Domain Specific Languages in Python
Creating Domain Specific Languages in Python
 
Desarrollando aplicaciones web en minutos
Desarrollando aplicaciones web en minutosDesarrollando aplicaciones web en minutos
Desarrollando aplicaciones web en minutos
 
Say Goodbye to Procedural Programming - Nick Sutterer
Say Goodbye to Procedural Programming - Nick SuttererSay Goodbye to Procedural Programming - Nick Sutterer
Say Goodbye to Procedural Programming - Nick Sutterer
 
Metaprogramming 101
Metaprogramming 101Metaprogramming 101
Metaprogramming 101
 
ISUCONアプリを Pythonで書いてみた
ISUCONアプリを Pythonで書いてみたISUCONアプリを Pythonで書いてみた
ISUCONアプリを Pythonで書いてみた
 
Where's My SQL? Designing Databases with ActiveRecord Migrations
Where's My SQL? Designing Databases with ActiveRecord MigrationsWhere's My SQL? Designing Databases with ActiveRecord Migrations
Where's My SQL? Designing Databases with ActiveRecord Migrations
 
Image manipulation in WordPress 3.5
Image manipulation in WordPress 3.5Image manipulation in WordPress 3.5
Image manipulation in WordPress 3.5
 
Rails 3 hints
Rails 3 hintsRails 3 hints
Rails 3 hints
 
Functional programming using underscorejs
Functional programming using underscorejsFunctional programming using underscorejs
Functional programming using underscorejs
 
Write your Ruby in Style
Write your Ruby in StyleWrite your Ruby in Style
Write your Ruby in Style
 
Groovy vs Boilerplate and Ceremony Code
Groovy vs Boilerplate and Ceremony CodeGroovy vs Boilerplate and Ceremony Code
Groovy vs Boilerplate and Ceremony Code
 
Be RESTful (Symfony Camp 2008)
Be RESTful (Symfony Camp 2008)Be RESTful (Symfony Camp 2008)
Be RESTful (Symfony Camp 2008)
 

Mehr von Kazuyuki CHINDA (7)

Introduction fasttext
Introduction fasttextIntroduction fasttext
Introduction fasttext
 
仮想電子工作のすすめ
仮想電子工作のすすめ仮想電子工作のすすめ
仮想電子工作のすすめ
 
Query selecterの話
Query selecterの話Query selecterの話
Query selecterの話
 
ウェブエンジニアのための色の話
ウェブエンジニアのための色の話ウェブエンジニアのための色の話
ウェブエンジニアのための色の話
 
Shinjuku.html5.lunch #11
Shinjuku.html5.lunch #11Shinjuku.html5.lunch #11
Shinjuku.html5.lunch #11
 
時間をかけて解く FizzBuzz
時間をかけて解く FizzBuzz時間をかけて解く FizzBuzz
時間をかけて解く FizzBuzz
 
エンジニアのためのUX入門
エンジニアのためのUX入門エンジニアのためのUX入門
エンジニアのためのUX入門
 

Kürzlich hochgeladen

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 

Kürzlich hochgeladen (20)

Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptx
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)
 
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 

typo の傾向と対策

  • 1. typo 2012-02-22 kchinda@aiming-inc.com (a.k.a. @ckazu)
  • 2. about me • @ckazu • • G • Rails • Rails + JS • Rails, Ruby 17
  • 5.
  • 10. • User.count → User.coutn
  • 11. 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   end end https://gist.github.com/1870273
  • 12. require 'typo_fixer' class Sample   include TypoFixer   def some_method     'some value'   end end sample = Sample.new p sample.sme_motoehd #=> 'some value' p sample.sme_motoehd.reveres #=> error! https://gist.github.com/1870273
  • 13. require 'typo_fixer' class Object   include TypoFixer end p [1, 2, 3].shaflfe.joni #=> "213" https://gist.github.com/1870273
  • 14. • User.count → User.caunt
  • 15. 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   end end https://gist.github.com/1883331
  • 16. require 'typo_fixer' class Object   include TypoFixer end p "some string".revarse #=> "gnirts emos" https://gist.github.com/1870273
  • 17. • array.flatten → array.flaten
  • 18.
  • 19. • car.control → car.controll
  • 20.
  • 21. • User.fin_dvy_id(di)
  • 22.
  • 23. method typo
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.