Data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 7387c8f97b
commit cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions

View file

@ -0,0 +1,9 @@
original = "hello"
reference = original # copies reference
copy1 = original.dup # instance of original.class
copy2 = String.new(original) # instance of String
original << " world!" # append
p reference #=> "hello world!"
p copy1 #=> "hello"
p copy2 #=> "hello"

View file

@ -0,0 +1,7 @@
original = "hello".freeze # prevents further modifications
copy1 = original.dup # copies contents (without status)
copy2 = original.clone # copies contents (with status)
p copy1.frozen? #=> false
p copy1 << " world!" #=> "hello world!"
p copy2.frozen? #=> true
p copy2 << " world!" #=> can't modify frozen String (RuntimeError)