Understanding the "difference" in Ruby
Finally got some time to write a little more about Ruby today. Well, in this wonderful time of learning this language, there has been one thing that i have been finding difficult to digest and embed as a part of my thinking. And while it matches the way i perceive programming languages to be, it is still requiring a little "getting used to".
What i am talking about is, treating everything as a Method or a message that takes input and returns a result.
Treating Operators, if-elsif-else statements and the likes, as methods is one thing. Coding them in that manner is completely different, and i am talking specifically about the kind of syntax that can come into play here.
Eg:
[sourcecode language="ruby"]
at_hotel = true
email = if at_hotel
address = "why"
address << "@hotelambrose"
address << ".com"
end
[/sourcecode]
the if statement here actually returns a value. And it returns the value of address. This is a little different from what you would normally see.
[sourcecode language="ruby"]
code_words['catapult']
#is actually the shorthand for
code_words.[]( 'catapult' )
[/sourcecode]
[sourcecode language="ruby"]
approaching_guy == false
#is the short hand for
approaching_guy.==( true )
[/sourcecode]
These are some different and unconventional coding syntaxes i have never come across, before Ruby. So, it is taking some time, but i am getting there. :)