0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

第3回つぶやき勉強会 ~オブジェクトの地図~

0
Last updated at Posted at 2016-11-11
Page 1 of 7
復習
class Hoge
  fuga = 1
  def fuga; 2; end
  def piyo
    fuga
  end
end
hoge = Hoge.new
  • hoge.piyo はなんですか?

class MyClass
  def my_method
    @v = 1
  end
end
obj = Hoge.new
  • obj.class.class.superclass.class はなんですか?

class Hoge
end
  • Hoge は変数 or 定数?
  • また、それを示せ。

class Hoge
  class Piyo
   def piyo; 1; end
  end
end
  • こんな書き方は可能ですか?
  • Piyo のインスタンスを作る方法は?

class Hoge
  private 
  def hoge
    1 
  end
end
  • プライベートメソッドをclass外から2パターンの方法で呼んでください。

解答

  • 2
  • Class
  • 定数, Object.constants.grep(/Hoge/)
  • 可能, Hoge::Piyo.new
  • obj.send(:hoge), Hoge.new.method(:hoge).call
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?