Rails .megabytes method returns wrong value
Where is "megabytes" method for fixnums defined? As far as I understand, its not a core ruby method, since its only available in rails.
ruby -e 'puts 5.megabytes'
In default rails installation it returns:
Loading development environment (Rails 2.3.8)
>> 5.megabytes
=> 52开发者_JS百科42880
At some point in my app something wrong happen, and now megabytes returns wrong values...
Loading development environment (Rails 2.3.8)
>> 5_000_000
=> 5000000
>> 5.megabytes
=> 5120
>> 5.kilobytes
=> 5
>> 5.bytes
=> 5
I am guessing some gem did something very wrong, but Its hard for me to track it to the source now.
Any idea how to find out where is the problem located?
Problem was in god gem, which was overwriting those methods in Numeric for unknown reason. This could easily break the app totaly, since I have lots of validations based on those methods. run
There is no need in general to include god in the app itself, but some people might in order to automate deployment...
I read some info about the gem, and people generally suggest it is quite broken in general due to lots of memory leaks. Any suggestions about this?
Ouch. Now I know why my 100.megabytes I was trying to render into a Flash uploader broke, cause it was accepting bytes and not kilobytes. It broke after I added the God gem to the Gemfile. That's VERY dangerous indeed.
An alternative to God is Bluepill. Bluepill has been created out of frustration with God. Here is a nice summary of why Bluepill was created http://asemanfar.com/Why-We-Wrote-Bluepill of course this is available as a gem so you could use this instead. The GitHub repository is linked to in the article as well.
I am now considering making the switch. Thanks for the heads up!
Not entirely on topic, since it's regarding the bytes converter, but since it's related to process monitoring and God is the cause, it might be useful to other than stumble upon this issue.
Hope this helps.
精彩评论