Permalink
Browse files

study over

  • Loading branch information...
herosea committed Feb 15, 2012
1 parent d6237a2 commit 9bab39f8b5f47ae052b63d33a2e943582cd8255f
Showing with 37 additions and 0 deletions.
  1. +15 −0 rubylearning.com/p047classaccess.rb
  2. +22 −0 rubylearning.com/p047zclassaccess.rb
@@ -0,0 +1,15 @@
+# p047classaccess.rb
+class ClassAccess
+ def m1 # this method is public
+ end
+ protected
+ def m2 # this method is protected
+ end
+ private
+ def m3 # this method is private
+ end
+end
+ca = ClassAccess.new
+ca.m1
+#ca.m2
+#ca.m3
@@ -0,0 +1,22 @@
+# p047zclassaccess.rb
+class Person
+ def initialize(age)
+ @age = age
+ end
+ def age
+ @age
+ end
+ def compare_age(c)
+ if c.age > age
+ "The other object's age is bigger."
+ else
+ "The other object's age is smaller or same."
+ end
+ end
+ protected :age
+end
+
+chris = Person.new(25)
+marcos = Person.new(34)
+puts chris.compare_age(marcos)
+#puts chris.age

0 comments on commit 9bab39f

Please sign in to comment.