Creation of a new object occurs in the non-mutating methods.
Eg:
Example 1
def fix(value)
value = value.upcase
value
end
s = "hello"
t = fix(s)
s = "hello" , object id : 100
t = "HELLO", object id : 200
Example 2
def fix(value)
value = value.upcase!
value
end
s = "hello"
t = fix(s)
s = "HELLO" , object id : 100
t = "HELLO", object id : 100
Eg:
Example 1
def fix(value)
value = value.upcase
value
end
s = "hello"
t = fix(s)
s = "hello" , object id : 100
t = "HELLO", object id : 200
Example 2
def fix(value)
value = value.upcase!
value
end
s = "hello"
t = fix(s)
s = "HELLO" , object id : 100
t = "HELLO", object id : 100
Comments
Post a Comment