Method: CShadow.append_features

Defined in:
lib/cgen/cshadow.rb

.append_features(base_class) ⇒ Object

:nodoc:



977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
# File 'lib/cgen/cshadow.rb', line 977

def self.append_features base_class # :nodoc:
  unless base_class.is_a? Class
    raise TypeError, "CShadow can be included only in a Class"
  end

  unless base_class.ancestors.include? self
    base_class.class_eval {@base_class = self; @persistent = true}
    base_class.extend CShadowClassMethods

    class << base_class
      ## why can't these be in CShadowClassMethods?

      alias really_protected protected
      def protected(*args)
        (@to_be_protected ||= []).concat args
      end

      alias really_private private
      def private(*args)
        (@to_be_private ||= []).concat args
      end

      def protect_shadow_attrs
        if defined?(@to_be_protected) and @to_be_protected
          really_protected(*@to_be_protected)
        end
        if defined?(@to_be_private) and @to_be_private
          really_private(*@to_be_private)
        end
        ## should undo the aliasing
      end
      public :protect_shadow_attrs

    end

  end

  super
end