Ruby : Writing Very long string in multiple lines

Using backward slash (\) at the end of line tells the ruby parser that the line is still incomplete. Also the parser concatenates the two string into one.

> long_sentence = "This is a very long sentence and this line even cannot"\
> " be written in one line"
 => "This is a very long sentence and this line even cannot be written in one line"

 

Ruby : Accessing Hash keys as String or Symbol

You might have notices or not but if you define a Hash instace with keys in ‘String’ then you cannot access then via :symbol and vice-versa

To be more clear see the following code snippet

Continue reading

Ruby : Similarity and Difference between Symbol and String with facts

No matter how they behave, Symbol and String in Ruby are alike. We can define Symbols as a type of String ( just according to behavior ). We often use them interchangeably in our code knowingly or unknowingly. Its has been said that Symbols are better than String however many of us are unaware about the core reasons. Continue reading