-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexamples.rb
More file actions
94 lines (71 loc) · 1.76 KB
/
examples.rb
File metadata and controls
94 lines (71 loc) · 1.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# frozen_string_literal: true
require "hooki"
module Examples
module ModuleWithHooki
include Hooki
before_singleton_method :before_singleton_log
after_singleton_method :after_singleton_log
def self.included(klass)
klass.extend(ClassMethods)
end
module ClassMethods
def save
puts "singleton save"
end
def before_singleton_log(method_name)
puts "before singleton #{method_name} log"
end
def after_singleton_log(method_name)
puts "after singleton #{method_name} log"
end
end
end
module ModuleIncludingModuleWithHooki
include ModuleWithHooki
def self.another
puts "singleton another"
end
end
class ClassWithHooki
include Hooki
before_singleton_method :before_singleton_log
after_singleton_method :after_singleton_log
def self.save
puts "singleton save"
end
def self.before_singleton_log(method_name)
puts "before singleton #{method_name} log"
end
def self.after_singleton_log(method_name)
puts "after singleton #{method_name} log"
end
before_method :before_instance_log
after_method :after_instance_log
def save
puts "instance save"
end
private
def before_instance_log(method_name)
puts "before instance #{method_name} log"
end
def after_instance_log(method_name)
puts "after instance #{method_name} log"
end
end
class Inheriting < ClassWithHooki
def self.another
puts "singleton another"
end
def another
puts "instance another"
end
end
class InheritingAgain < Inheriting
def self.another_again
puts "singleton another_again"
end
def another_again
puts "instance another_again"
end
end
end