RubyGold試験の勉強の時に作成した自習問題
・過去に作成したものなのでコードの説明はありません(出来ない…)。
・実行結果をコメントとして記述しています(コード #=> 結果)。
・右往左往しているのでコードにもコメント化している箇所があります。

→ 「他の問題


#! ruby -Ks

#------------------------------------------------------------
# Gold模擬15.rb
# ■何を確認したいのか忘れました6
#------------------------------------------------------------

#--------------------------------------------------
# Define
#------------------------------
class A
  $a = self

  def hoge
    $b = self
  end

  def piyo
    $c = self.class
  end

end

#--------------------------------------------------
# Execute
#------------------------------
puts "----------1"
x = A.new
puts $a  #=> A
puts $b  #=>
puts $c  #=>
puts A.new  #=> #
puts "----------1-1"
puts A == $a  #=> true
puts A.new == $a  #=> false
puts A.new == $b  #=> false

puts "----------2"
x.hoge
puts $b  #=> #
puts A.new  #=> #
puts A.new.hoge  #=> #
puts "----------2-1"
puts A.new == $b  #=> false
puts A.new.hoge == $b  #=> true
puts A.new.hoge === $b  #=> true
puts "----------2-2"
puts x  #=> #
puts x.hoge  #=> #
puts x == x.hoge  #=> true

puts "----------3"
x.piyo
puts $c  #=> A
puts $c.new  #=> #
puts A.new  #=> #
puts "----------3-1"
puts A.new == $c  #=> false
puts A.new == $c.new  #=> false
puts A == $c  #=> true
puts $a == $c  #=> true

puts "----------4"
puts $c.class  #=>
puts "A".class  #=>

#----------
=begin
print "a = A.new"
a = A.new
print "A == $a -> ", (A == $a)
print "A.new == $b -> ", (A.new == $b)

print "a.hoge"
a.hoge
print "A.new == $b -> ", (A.new == $b)

print "a.piyo"
a.piyo
print "A.new == $b -> ", (A.new == $b)
=end

#------------------------------------------------------------
# END
#------------------------------------------------------------