Comments (8)
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.
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.
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.
Very nice 👍
from motion-support.
Pushed the changes to master
from motion-support.
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.
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.
Ahhh gotcha, makes sense.
from motion-support.
Related Issues (20)
- License missing from gemspec HOT 1
- detect_dependencies = false ? HOT 3
- Date/Time class not working as expected HOT 1
- Date to epoch time conversion issue HOT 6
- Can't locate iPhoneOS SDK 6.1 error HOT 4
- can't convert MotionSupport::Duration into an exact number HOT 7
- Is this still maintained? HOT 3
- API Doc link is not available anymore HOT 2
- When the newest version in github repo will be pushed to rubygems.org? HOT 3
- Date.today and Date.tomorrow do not equally convert to Time
- end of day or year rounding issues HOT 2
- Android support? HOT 3
- undefined method `+' for class `Date' (NameError) HOT 22
- undefined method `delegate' for NSDictionary:Class HOT 2
- hash with indifferent access fails with undefined method_defined? on Android HOT 1
- Silent crash using motion-support on Android HOT 1
- undefined method `mattr_writer' for MotionSupport:Class
- Crash when invoking .day
- Time for a version bump and gem push? HOT 8
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from motion-support.