Giter Site home page Giter Site logo

Comments (2)

matsadler avatar matsadler commented on August 27, 2024

So Ruby's C API has a bunch of functions to check a value is of a certain type (or convert it to that type with the implicit conversion methods, to_str, to_ary, etc).

There's some like rb_check_<type>_type that return the value if it's of that type, call to_<typ> if it responds to that method, or return nil if it can't be converted. Magnus looks for that nil and raises an error.

Then there's rb_str_to_str which returns the value if it's a string, calls to_str if the object responds to it, or errors if it can't be converted. This is convenient as then the code in Magnus doesn't have to do the extra nil check to return an error in the last case.

The array conversions are done using rb_ary_to_ary. Turns out this does not work like rb_str_to_str. Instead of erroring if the value can't be converted (or returning nil) it returns the value wrapped in an array.

In my defence, at the time I wrote this code the Ruby C API was totally undocumented (the headers now do document this potential confusion).

I've fixed this in 69ff299, but as it's a change in behaviour I'm going to put of releasing till 0.5.

from magnus.

gjtorikian avatar gjtorikian commented on August 27, 2024

In my defence, at the time I wrote this code the Ruby C API was totally undocumented (the headers now do document this potential confusion).

No worries at all! Thank you for the project, Iā€™m just calling what I see. šŸ˜„ Thanks for the quick fix!

from magnus.

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.