ruby学習ノート1


  • If a method is protected, it may be called by any instance of the defining class or its subclasses. If a method is private, it may be called only within the context of the calling object---it is never possible to access another object's private methods directly, even if the object is of the same class as the caller.
  • Ruby differs from other OO languages in another important way. Access control is determined dynamically, as the program runs, not statically. You will get an access violation only when the code attempts to execute the restricted method.
  • A class's initialize method is automatically declared to be private.
  • 異なるオブジェクトインスタンスにおける役割ドメインの異なるJavaでは、privateまたはprotectedの方法にかかわらず、同じカテゴリの他のオブジェクトインスタンスによって呼び出されることができる.Rubyではprivateメソッドは同じカテゴリの他のオブジェクトインスタンスによって呼び出されません.
  • クラス継承関係における役割ドメインの異なるrubyではprivateもprotected方法も布団クラス継承が可能である.Javaではprivateメソッドは布団類に継承できません.
  • この方法呼び出しの違いは、Javaのオブジェクト向けがC++から来て、クラス継承関係を強調しているため、メソッド呼び出しはクラス継承の階層構造の中の役割ドメインを限定するが、オブジェクトインスタンスの役割ドメインを強調しない.一方rubyのオブジェクト向けはsmalltalkから来ており,カテゴリでもオブジェクトであるため,メソッド呼び出し役割ドメインはオブジェクトインスタンス呼び出しに対して設定されている.

  • For Java--
    public:すべてのクラスが表示されます.pirvate:同じクラスの内部のメソッドのみが表示され、内部クラスでもアクセスできます.デフォルト(friendly):パッケージ内が表示されます.protected:表示を継承します.