I have following code
class User
attr_accessor :name
end
u = User.new
u.name = 'john'
puts u.name #=> john
In the above case everything works. However this code does not work
class User
attr_accessor :name
end
u = User.new
u.name = 'john'
u.name('john')
In order to fix that issue, I have decided to use alias_method. I know there are other ways to solve the problem, but I'm specifically looking if this problem could be solved using alias_method. Trying to learn.
Following code will work
class User
attr_accessor :name
alias_method :foo, :name=
end
u = User.new
u.foo('john')
puts u.name
However this code will not work for obvious reason.
class User
attr_accessor :name
alias_method :name, :name=
end
u = User.new
u.name('john')
puts u.name
Anyone knows if this problem can be fixed with alias_method.