I have two methods in my ruby class and I am trying to modify a local variable string on another method,
def modify_test
value = 'initial stringg'
remove_last_char(value)
puts value
end
def remove_last_char(value)
value = value[0...-1]
puts value
end
The remove_last_char method prints initial string but modify_test method prints initial stringg even after invoking the remove_last_char. I don't think that value = value[0...-1] is getting referenced to the parameterized value.
- Can I point to the same value after the modification of value on the
remove_last_charmethod? - Are there any alternatives to achieve such a case?
I have gone through this question as well and that has a similar case but not the duplicate one :)