Just-in-time libraries
When I was a younger fellow, I would dream up perfectly formed libraries. I would marvel at how beautiful they were and how clever I was. Sometimes I would actually use the library in a project, sometimes not.
As I got older I started to build “just-in-time libraries”, which are libraries that you build only when you need them during the actual creation of a real project.
These kind of libraries are not complete, aren’t as beautiful to behold, and often have pragmatic things that aren’t 100% consistent. However they are guaranteed to be used and are naturally optimized to solve the problems that actually exist.
The reason I’m telling you this little story is because RMQ 0.7 was just released with a new feature: validations. It, like the rest of RMQ, was born during frustration while working on an actual project.
Gant Laborde create the validations feature and it’s a cool one. Thank you Gant.
See RMQ news below for more info on validations.
If you missed the last issue, you can find it here: issue #39.
Happy coding, Todd Werth (@twerth)
Articles, News, New Gems, and Blog Posts
August 14th, 2014 | new meetup
“London RubyMotion meetup”
August 11th, 2014 | blog post | by Rob Horrigan
“RubyMotion 3.0: Android support”
August 11th, 2014 | screencast | by Jack Watson-Hamblin
“MotionInMotion – Episode 37 – Test Driven Development and Creating a Gem Part 2”
August 9th, 2014 | blog post | by Kamil Lelonek
“RubyMotion app with Facebook SDK”
August 8th, 2014 | blog post | by Lori Olson
“Static Tables in Code”
August 7th, 2014 | blog post | by Gant Laborde
“Dealing with bad data and the Hash structure’s defenses:”
RubyMotion App of the Week
Gems used in the app:
- bubble-wrap
- afmotion
- motion-cocoapods
- ib
- menu-motion
- motion_print
Pods used in the app:
- Mixpanel-OSX-Community
- Ono
RMQ News
Validations
Version 0.7 was just released. The major new feature is validations. They were created by Gant Laborde
Read the documentation here
# Examples of the Utility
rmq.validation.valid?('https://www.infinitered.com', :url) #true
rmq.validation.valid?(98.6, :number) #true
# Examples of Selection Rules
rmq.append(UITextField, :user).validates(:email)
rmq.append(UITextField, :password).validates(:strong_password)
rmq.append(UITextField, :pin).validates(:digits).validates(:length, exact_length: 5)
rmq(UITextField).valid? # checks if selected is valid
rmq(:password).clear_validations! #removes validations on selected
Hidden Gem by Gant Laborde
Avoiding begin/rescue
for Hashes
In RubyMotion, if you were to run the following application, you can get back with me on how it went in about week or so.
n = 5000
my_hash = {a: 1, b: 2}
n.times do
begin
z = my_hash.fetch(:z)
rescue
z = 26
end
end
Your REPL will be filled with n
KeyErrors that run slowwwwwwwwww. The way RubyMotion handles exceptions is a nightmare in this particular situation. Today’s hidden gem is that Hash#fetch
accepts a block. Instead you can write.
n = 5000
my_hash = {a: 1, b: 2}
n.times do
z = my_hash.fetch(:z) do
# do anything here. Runs if fetch fails
26
end
end
This runs all 5000 in under a second. It’s a silly example, but it proves a point. For more information on Hashes, see my latest blog post: Dealing with bad data and the Hash structure’s defenses
Sponsor
My company InfiniteRed sponsors this newsletter by allowing me the time to work on it every week and hosting everything.
Contact us if you ever need help working on a project, mentoring, or other development services . We specialize in RubyMotion and have an awesome team.
Wat!
In Ruby:
0.1 + 0.2 == 0.3
#=> false
However, RubyMotion is correct:
0.1 + 0.2 == 0.3
=> true
If you have any tips, blog posts, or comments, please send emails to todd@infinitered.com