每天的 1%
筆記一些每天學習到的東西,希望一年可以至少筆記 365 篇,一天 1% 一年就可以進步 37.8 倍
2018年4月26日 星期四
同時定義 class method 和 instance method 的潮潮寫法
You can delegate method to your `class` since your class is also a object in Ruby, fanny~
```ruby
class Foo
def self.bar
return "Hello"
end
delegate :bar, to: :class
end
```
```ruby
Foo.bar
# => "Hello"
Foo.new.bar
# => "Hello"
```
Awesome.
沒有留言:
張貼留言
較新的文章
較舊的文章
首頁
訂閱:
張貼留言 (Atom)
沒有留言:
張貼留言