diff options
Diffstat (limited to 'ruby/class_method.rb')
-rwxr-xr-x | ruby/class_method.rb | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/ruby/class_method.rb b/ruby/class_method.rb new file mode 100755 index 0000000..447a477 --- /dev/null +++ b/ruby/class_method.rb @@ -0,0 +1,36 @@ +#!/usr/bin/env ruby + + +class A + attr_accessor :z + + def initialize + self.z = 'a' + end + + def self.a + r = self.new + return r + end +end + +class B < A + + def initialize + self.z = 'b' + end + + def b + "b" + end +end + +a = A.new +b = B.new + +puts a.z +puts b.z +puts +x = B.a +puts x.z + |