Coder Social home page Coder Social logo

did_you_mean's Introduction

did_you_mean Gem Version Build Status

'Did you mean?' experience in Ruby. No, Really.

Installation

Add this line to your application's Gemfile:

gem 'did_you_mean', group: [:development, :test]

Examples

NameError

Correcting a Misspelled Method Name

class User
  attr_accessor :first_name, :last_name

  def to_s
    "#{f1rst_name} #{last_name}" # f1rst_name ???
  end
end

user.to_s
# => NameError: undefined local variable or method `f1rst_name' for #<User:0x0000000928fad8>
#
#     Did you mean? #first_name
#

Correcting a Misspelled Class Name

class Book
  class TableOfContents
    # ...
  end
end

Book::TableofContents # TableofContents ???
# => NameError: uninitialized constant Book::TableofContents
#
#     Did you mean? Book::TableOfContents
#

NoMethodError

# In a Rails controller:
params.with_inddiferent_access
# => NoMethodError: undefined method `with_inddiferent_access' for {}:Hash
#
#     Did you mean? #with_indifferent_access
#

ActiveRecord::UnknownAttributeError

User.new(nmee: "wrong flrst name")
# => ActiveRecord::UnknownAttributeError: unknown attribute: nmee
#
#     Did you mean? name: string
#

'Did You Mean' Experience is Everywhere

did_you_mean gem automagically puts method suggestions into the error message. This means you'll have the "Did you mean?" experience almost everywhere:

Did you mean? on BetterErrors

Support

did_you_mean gem supports the following implementations:

  • MRI 1.9.3, 2.0.0, 2.1.x, 2.2.0-preview1 and ruby-head
  • JRuby (tested against 1.7.16)

Any other implementations are NOT supported (Rubinius support is work in progress).

Contributing

  1. Fork it (http://github.com/yuki24/did_you_mean/fork)
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

License

Copyright (c) 2014 Yuki Nishijima. See MIT-LICENSE for further details.

did_you_mean's People

Contributors

fortissimo1997 avatar tbpgr avatar yuki24 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.