For those who don’t know, it has been 3 months since I am working with Slideshare. I have never written code in ruby before Slideshare and always involved in development with low-level languages like C/C++. Here I have a chance of writing code in Ruby and I’m loving it.
Since few days, we were wondering why our Cache was not being flushed even we have done everything right over there. What we were doing was to check a Boolean variable (true, false, nil) and based on that we were deciding to flush cache or not. The code used to look as below:
var = true
#it wasn't working
if var == 1
Flsuh_data_from_Cache
end
We were suspecting everything ok since we start looking into the problem and was wondering why this flush request is not working. Ultimately after some real time debugging, the reason of failure was that in Ruby TRUE is not equal to 1. I was surprised that many people didn't know this fact and use this kinda check at many places. Finally, we have to change our code like below to get it in action.
var = true
#it worked
if var
Flsuh_data_from_Cache
end
After seeing this. Again this isn’t the only thing that surprised me but many more similar things are there to baffle you.
PS: I am still looking for some good resource on how variables are stored in memory in Ruby. If someone can get me an idea of that, I will be highly grateful to him/her.
Subscribe - To get an automatic feed of all future posts subscribe here, or to receive them via email go here and enter your email address in the box. You can also like us on facebook and follow me on Twitter @akashag1001.
It’s worth noting that only Ruby object that is false in a boolean context, apart from false itself:
>> if nil
>> true
>> else
>> false # nil is false
>> end
=> false
In particular, all other Ruby objects are true, even 0:
>> if 0
>> true # 0 (and everything other than nil and false itself) is true
>> else
>> false
>> end
=> true
Source: RailsTutorial
Amazing Post. The choice of words is very unique. Interesting idea. Looking forward for your next post.
Hadoop Admin Training in Chennai
Hadoop Administration Training in Chennai
Hadoop Administration Course in Chennai
Hadoop Administration Training
Big Data Administrator Training
IELTS coaching in Chennai
IELTS Training in Chennai
SAS Training in Chennai
SAS Course in Chennai