Reputation:
Ruby noob, just got and installed RubyMotion, created my first program and I'm having trouble getting the Time (sample) app to work.
Whenever I try to format a string using either sprint or the other form (sorry don't know the name) I just get my format string back.
i.e. (from the console while my app is running in Simulator)
Build ./build/iPhoneSimulator-5.1-Development
Simulate ./build/iPhoneSimulator-5.1-Development/Timer.app
(main)>> @time = 0.1
=> 0.0999999940395355
(main)>> string = sprintf("%.1f", @time)
=> "%.1f"
(main)>> string
=> "%.1f"
(main)>> "%.1f" % @time
=> "%.1f"
(main)>>
The same result in the actual app in the Simulator.
I do have the default ruby installed on my Mac but if I try running a test ruby file (print "%05d" % 123) I get expected results.
/usr/bin/ruby -v
ruby 1.8.7 (2010-01-10 patchlevel 249) [universal-darwin11.0]
/Library/RubyMotion/bin/ruby -v
MacRuby 0.12 (ruby 1.9.2) [universal-darwin11.0, i386]
Running on Lion 10.7.3, any advice or ideas appreciated.
Thanks.
Upvotes: 3
Views: 451
Reputation: 124449
As of 5/9/12, this has been fixed. Make sure you're on RubyMotion 1.3 (run sudo motion update
) and string formatting will work again.
Update 5/8/12: Confirmed bug, should be fixed this evening or tomorrow.
Per my comments above, there is definitely a bug with this. An ugly hack to get this working could be something like this (since %d
still works fine for sprintf
):
@time = 0.1
sprintf("%d", (@time * 10).round).insert(-2, '.')
Upvotes: 1