Hi All,
I want to create a alias method in ruby and pass parameters to this. I managed to do the following
class User
def say_name
puts "I'm sameera"
end
end
class User
alias :tell_name :say_name
def say_name
puts "I'm sameera gayan"
tell_name
end
end
user = User.new
user.say_name
and it gives me the out put as
I'm sameera gayan I'm sameera
But now i want to pass my name as a parameter to the first 'say_name' method. So the new code will be like
class User
def say_name(name)
puts "#{name}"
end
end
class User
alias :tell_name :say_name(name)
def say_name(name)
puts "I'm sameera gayan"
tell_name(name)
end
end
user = User.new
user.say_name("my new name")
But now this doesn't work (passing parameter to alias method). So my question is how to pass parameters to an alias method.
I hope this question is clear to you. Thanks in advance
cheers
sameera