Learning Ruby

Consider this example from the Programming Ruby book:

class Account
  attr_reader :balance       # accessor method ‘balance’
  protected :balance         # and make it protected
  def greaterBalanceThan(other)
    return @balance > other.balance

Q:  How do I know that “other” is a type of Account? 
Q:  Wouldn’t it be a lot clearer if you always declared the instance variables, so you could see at a glance what variables you have?  And while you are declaring the variable, you specify the access modifier? 

Is the following really more clear – or am I just used to it?

protected double cleared_balance
get { return _cleared_balance; }
private set { _cleared_balance = value; }

Obviously, I don’t “get” dynamic languages.  Will I ever?  (to be continued…)


Post a Comment

Required fields are marked *

%d bloggers like this: