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.

沒有留言:

張貼留言