In the code below, I have given a default value for the accountNumber for when it is not called with a particular value but that value is not recognized by the code, why is that?
class BankAccount
CONST=0100
def interest_rate
@@interest_rate = 0.2
end
def accountNumber
@accountNumber
end
def accountNumber=(value = 10)
puts value
@accountNumber = value
end
end
When I call the accountNumber= method as below with no arg, I expect it to puts “10” but it is not putting out the default value…
account1 = BankAccount.new()
puts account1.accountNumber=()
I cannot be fully sure, but it seems to be some irregularity due to the method name ending with
=. That type of methods do not seem to accept default values correctly. When you change the method name toset_account_number, then it will work.