Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
22
Task/String-concatenation/Ruby/string-concatenation.rb
Normal file
22
Task/String-concatenation/Ruby/string-concatenation.rb
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
s = "hello"
|
||||
|
||||
puts "#{s} template" #=> "hello template"
|
||||
# Variable s is intact
|
||||
puts s #=> "hello"
|
||||
|
||||
puts s + " literal" #=> "hello literal"
|
||||
# Variable s is still the same
|
||||
puts s #=> "hello"
|
||||
|
||||
# Mutating s variable:
|
||||
|
||||
s += " literal"
|
||||
puts s #=> "hello literal"
|
||||
s << " another" # append to s, use only when string literals are not frozen
|
||||
puts s #=> "hello literal another"
|
||||
|
||||
s = "hello"
|
||||
puts s.concat(" literal") #=> "hello literal"
|
||||
puts s #=> "hello literal"
|
||||
puts s.prepend("Alice said: ") #=> "Alice said: hello literal"
|
||||
puts s #=> "Alice said: hello literal"
|
||||
Loading…
Add table
Add a link
Reference in a new issue