我正在学习 ruby,我专门在其中玩 OOPS。我正在尝试在 ruby 中编写与此 PHP 代码等效的代码
    class Abc {
        $a = 1;
        $b = 4;
        $c = 0;
        function __constructor($cc) {
            $this->c = $cc
        }
        function setA($v) {
            $this->a = $v
        }
        function getSum() {
            return ($this->a + $this->b + $this->c);
        }
    }
    $m = new Abc(7);
    $m->getSum(); // 12
    $m->setA(10);
    $m->getSum(); // 21
我正在尝试将相当于上述 PHP 的内容编写为 ruby。请注意,我的目标是拥有类变量的 soem 的默认值,如果我想覆盖它,那么我可以通过调用 getter/setter 方法来实现。
    class Abc 
        attr_accessor :a
        def initialize cc
            @c = cc
        end
        def getSum 
            #???
        end
    end
我不喜欢做
Abc.new(..and pass value of a, b and c)
我的目标是拥有默认值,但如果需要,它们可以通过实例进行修改。