「Ruby/class」の版間の差分
提供: 初心者エンジニアの簡易メモ
(ページの作成:「==クラスとメソッド== class TestController def hello end end ==継承の仕方== class TestController < ApplicationController def hello end end」) |
(→継承の仕方) |
||
| 行9: | 行9: | ||
def hello | def hello | ||
end | end | ||
| + | end | ||
| + | |||
| + | ==プロパティ== | ||
| + | class TestService | ||
| + | def initialize(name) | ||
| + | @name = name | ||
| + | end | ||
| + | def exec() | ||
| + | return @name | ||
| + | end | ||
| + | attr_accessor :name | ||
end | end | ||
2017年11月8日 (水) 03:51時点における版
クラスとメソッド
class TestController def hello end end
継承の仕方
class TestController < ApplicationController def hello end end
プロパティ
class TestService
def initialize(name)
@name = name
end
def exec()
return @name
end
attr_accessor :name
end
