How can I use underscores instead of camelCase in RubyMotion?

I've found that using a camel case reduces readability and reusability at the same time in some scenarios when working with RubyMotion

. While I understand how it was, from the outset, useful from Cocoa in order to preserve this convention, it seems to me that it would be more productive and sensible to use word delimitation in the standard Ruby convention. Is there a way to do this or is there another way to attack this issue?

ActiveSupport supports this conversion. I see something from BubbleWrap that has methods camelize

and underscore

, but obviously it doesn't really target this particular use case.

It seems that if that's not what the RubyMotion folks will provide themselves, perhaps we could write a wrapper method so that precompilation can be initiated to do this conversion?

+3


source to share


2 answers


I've written inflectors that do this kind of thing, and using them automatically makes me really nervous. If you really want to use inflectors take a look at the motion-support

gem
. It contains camelize

, underscore

and a bunch of other sharp things. You will notice that these inflectors can be overridden, where the defaults just don't work. This is problem. Where it doesn't work.

Inflectors work on a heuristic basis. Most good heuristics cover most of the known cases; there are exceptions. These are the exceptions that will really kill you. (Note: the ones I prepared and added to support the movement were based on the rules of English grammar. You can imagine how difficult localization is!)

If you think RubyMotion will do this conversion automatically, I think many programmers will find it intuitive, because they would have written: tableView(view, numberOfRowsInSection:section)

and somehow messed it up. The error message can be read:



table_view:number_of_rows_in_section: *** You made some mistake ***

      

This will not show up in the code as written.

I don't think you want your build tools to rename your objects and / or methods without permission and how does RubyMotion know what to rename and which not?

+1


source


There is a gem for this: https://github.com/jamonholmgren/viper

It's nice to have the option you choose. However, I will consider the future of the project. For example, imagine that your project is successful and you hire more Objective-C developers to work with you on this project. It will be easier for them to port it to Objective-C (or Swift) if they are familiar with it. Some of the junior developers who don't know Cocoa will struggle well with Googling for the right answer.



As a result, I confused cocoaMethod(calls)

with my_own_ruby_method(calls)

.

0


source







All Articles