Last active
September 16, 2015 13:58
-
-
Save pyrabbit/1eb85febc00b89f64beb to your computer and use it in GitHub Desktop.
This is an example showing how the String#replace method retains the same object id after being called.
This file contains hidden or 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
> a = "This is a cat" | |
=> "This is a cat" | |
> a.__id__ | |
=> 7971260 | |
> b = "This is a dog" | |
=> "This is a dog" | |
> b.__id__ | |
=> 7965700 | |
> a = b.replace("This is a bird") | |
= "This is a bird" | |
> a.__id__ | |
=> 7965700 | |
> b.__id__ | |
=> 7965700 | |
> puts a, b | |
This is a bird | |
This is a bird | |
=> nil |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment