README.md in tiny_hooks-1.0.0 vs README.md in tiny_hooks-2.0.0

- old
+ new

@@ -1,5 +1,7 @@ +[![Ruby](https://github.com/okuramasafumi/tiny_hooks/actions/workflows/main.yml/badge.svg)](https://github.com/okuramasafumi/tiny_hooks/actions/workflows/main.yml) + # TinyHooks A tiny gem to define hooks. ## Installation @@ -34,9 +36,49 @@ puts 'my before hook' end end MyClass.new.my_method +# => "my before hook\nmy method\n" +``` + +You can also call `define_hook` with method name as a third argument. + +```ruby +class MyClass + include TinyHooks + + def my_method + puts 'my method' + end + + def my_before_hook + puts 'my before hook' + end + + define_hook :before, :my_method, :my_before_hook +end + +MyClass.new.my_method +# => "my before hook\nmy method\n" +``` + +You can define hooks for class methods as well. + +```ruby +class MyClass + include TinyHooks + + def self.my_method + puts 'my method' + end + + define_hook :before, :my_method, class_method: true do + puts 'my before hook' + end +end + +MyClass.my_method # => "my before hook\nmy method\n" ``` TinyHooks shines when the class/module is the base class/module of your library and your users will inherit/include it. In these cases, end users can define hooks to the methods you provide. The only thing you have to do is to provide the list of methods.