summaryrefslogtreecommitdiff
path: root/ruby/class_method.rb
blob: 447a477c55066f03793a4b46b2edbfa9c6ec9dea (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
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