Coder Social home page Coder Social logo

Comments (8)

tkadauke avatar tkadauke commented on June 23, 2024

I agree. I didn't do it yet, since I didn't need it so far.
There are basically two different ways to do that. One, like you said, add everything to NSString/NSMutableString. Two, leave things in String, and add a to_s method to NSString, giving the responsibility back to the user. Two point five would be to also add all the methods to NSString/NSMutableString, but delegate the calls to to_s. An example of the last one can be found in motion/core_ext/ns_dictionary.rb

What do you think?

from motion-support.

clayallsopp avatar clayallsopp commented on June 23, 2024

Hmmm, I don't like just using to_s because it can lead to a lot of unexpected behavior (i.e. you create a User object with String fields, serialize it, deserialize it, everything is now an NSString and you have to remember to coerce the fields back with to_s at some point). Would lead to a lot of surprises just because of a technical detail in how RubyMotion is implemented, and folks without a Cocoa background won't immediately understand why. I can already see the Github Issues popping up :)

But the delegation scheme could work...I guess the drawback is when new extensions are added, you have to remember to also add a corresponding method to the right core_ext file? Instead of just writing it in one place and being done with it. And that's not necessarily a bad thing, since new extensions won't be super common; just trying to make sure that's the only downside.

So yeah tl;dr either solution 1 or solution 2.5 sound good

from motion-support.

tkadauke avatar tkadauke commented on June 23, 2024

Check out my commit in branch ns_string. This has the additional advantage that whenever you use an extension to class String that returns a different string, you're guaranteed to end up with a Ruby String instance instead of a NSString instance. What do you think?

from motion-support.

clayallsopp avatar clayallsopp commented on June 23, 2024

Very nice 👍

from motion-support.

tkadauke avatar tkadauke commented on June 23, 2024

Pushed the changes to master

from motion-support.

clayallsopp avatar clayallsopp commented on June 23, 2024

Hmmm, I think there's a bug in the implementation for multiple-argument methods:

(main)> "camel_case".camelize(true)
=> nil
(main)> "camel_case".camelize(false)
=> nil

# vs.
(main)> MotionSupport::Inflector.camelize("camel_case", true)
=> "CamelCase"
(main)> MotionSupport::Inflector.camelize("camel_case", false)
=> "camelCase"

from motion-support.

tkadauke avatar tkadauke commented on June 23, 2024

Hmm I agree it is unexpected, but it's just like in ActiveRecord. It should be

"camel_case".camelize(:lower)
"camel_case".camelize(:upper)

from motion-support.

clayallsopp avatar clayallsopp commented on June 23, 2024

Ahhh gotcha, makes sense.

from motion-support.

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.