ruby---クラスメソッド定義

845 ワード


# -*- coding: utf-8 -*-
# ruby          

=begin
   : def   .   ~end"
=end
class HelloWorld
  def HelloWorld.hello(name)
    print name, " said Hello."
  end
end

jack = HelloWorld.hello("jack")

=begin
   : class <<   ~def    ~end end"
=end
class HelloWorld2
  
end
class << HelloWorld2
  def hello(name)
    print name, " said Hello2."
  end
end

tony = HelloWorld2.hello("tony")

=begin
   : class   ~def self.   ~end end
=end
class HelloWorld3
  def self.hello(name)
    print name, " said Hello3."
  end
end
cherry = HelloWorld3.hello("cherry")