Created
August 14, 2011 23:33
-
-
Save sriranggd/1145457 to your computer and use it in GitHub Desktop.
Ruby -- issues with unary + used on strings
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ ./irb | |
>> def ret_str | |
>> "hello " | |
>> end | |
=> nil | |
>> @ins_var = "world" | |
=> "world" | |
>> ret_str +@ins_var | |
NoMethodError: undefined method `+@' for "world":String | |
from (irb):5 | |
from ./irb:12:in `<main>' | |
>> ins_var | |
NameError: undefined local variable or method `ins_var' for main:Object | |
from (irb):6 | |
from ./irb:12:in `<main>' | |
>> self.ins_var | |
NoMethodError: undefined method `ins_var' for main:Object | |
from (irb):7 | |
from ./irb:12:in `<main>' | |
>> "hello " +@ins_var | |
=> "hello world" | |
>> str = "hello " | |
=> "hello " | |
>> str +@ins_var | |
=> "hello world" | |
>> ret_str+@ins_var | |
=> "hello world" | |
>> str = "world" | |
=> "world" | |
>> ret_str +str | |
NoMethodError: undefined method `+@' for "world":String |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment