クラスを作る
class Hello def initialize(myname="ruby") @name = myname end def hello print "hello,world. I am ", @name, ".\n" end bob = Hello.new("bob") alice = Hello.new("alice") ruby = Hello.new bob.hello alice.hello bob.hello ruby.hello end
結果
hello,world. I am bob.
hello,world. I am alice.
hello,world. I am bob.
hello,world. I am ruby.