[Ruby]クラスのinitializeのサンプル

書式
def initialize
@変数名=xxx
end
使用例

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
#!/usr/bin/ruby
class Test
def initialize
@msg = "study skill in arkgame become smart"
end
def funcA
p @msg
end
end
cft = Test.new
cft.funcA
#!/usr/bin/ruby class Test def initialize @msg = "study skill in arkgame become smart" end def funcA p @msg end end cft = Test.new cft.funcA
#!/usr/bin/ruby
class Test
 
  def initialize
    @msg = "study skill in arkgame become smart"
  end
 
  def funcA
    p @msg
  end
 
end
 
cft = Test.new
cft.funcA

結果
“study skill in arkgame become smart"

Ruby

Posted by arkgame