Skip to content

Instantly share code, notes, and snippets.

@pyrabbit
Last active September 16, 2015 13:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pyrabbit/1eb85febc00b89f64beb to your computer and use it in GitHub Desktop.
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.
> 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