I have one string which is contain char like "Pi#$e77L09!($".
But when i tried to print on Console its prints like "Pi!($"
2.1.2 :002 > str = "Pi#$e77L09!($" => "Pi!($"
2.1.2 :003 > puts str Pi!($ => nil
str = "Pi#$e77" /> str = "Pi#$e77" /> str = "Pi#$e77"/>
I have one string which is contain char like "Pi#$e77L09!($".
But when i tried to print on Console its prints like "Pi!($"
2.1.2 :002 > str = "Pi#$e77L09!($" => "Pi!($"
2.1.2 :003 > puts str Pi!($ => nil
The magic is in
#. As you know"#{ ruby code }"executes the code in the block and prints it. Similarly, # allows you to access global variables of a program by putting a hash in front of it like so"#$a".so if you try this code.
you will see that it prints test. So in your case since
$e77L09is a non-existent global variable it prints nothing.if you want to print that string as a string you will need to print it in single quotes. 'Pi#$e77L09!($'
The above usage of "#$1 #$2" is really useful when you use regex. When a string has multiple matching regex it becomes accessible using $1, $2, $3, etc. This stuff came from the Perl world I believe (I am not 100% sure about its history).
EDIT: Like Global Variable supports class and instance variables can be accessed as well.