GithubHelp home page GithubHelp logo

Comments (4)

jmanian avatar jmanian commented on July 25, 2024 1

I did a little digging and it turns out that it used to do what the comment says, and it was even implemented with key? at that time. It was changed to the current behavior intentionally way back in 2010 with 5a53de5, in response to #4.

5a53de5 also added a note to the readme to explain the behavior, and the note is still there today. But it left the original comment in place, which described the old behavior.

So I'll submit a PR to change the comment to something like this:

 # * Truthiness (<tt>?</tt>): Returns true or false depending on the truthiness of
 #   the attribute, or false if the key is not set.

from hashie.

dblock avatar dblock commented on July 25, 2024 1

The moral of the story is to not document your code.

from hashie.

dblock avatar dblock commented on July 25, 2024

Oh my. I bet the original intent was presence, but this is obviously not what we have implemented.

Could you see what specs we break if the behavior actually does what the comment says? I am going to assume it's a lot, in which case let's change the comment and document in README.

from hashie.

michaelherold avatar michaelherold commented on July 25, 2024

It breaks a single test that is explicitly testing that behavior:

it 'returns false on a ? method if a value has been set to nil or false' do
subject.test = nil
expect(subject).not_to be_test
subject.test = false
expect(subject).not_to be_test
end

I believe query methods are for truthiness checks against the value at the key.

from hashie.

Related Issues (20)

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.