Module: Kind::Functional::ClassMethods
Class Method Summary
collapse
Instance Method Summary
collapse
#__dependencies__, #dependency
Class Method Details
.inherited(_) ⇒ Object
73
74
75
|
# File 'lib/kind/functional.rb', line 73
def self.inherited(_)
raise RuntimeError, "#{self.name} is a Kind::Functional and it can't be inherited by anyone"
end
|
Instance Method Details
#kind_functional! ⇒ Object
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
|
# File 'lib/kind/functional.rb', line 54
def kind_functional!
return self if Kind.is?(Behavior, self)
public_methods = self.public_instance_methods - ::Object.new.methods
unless public_methods.include?(:call)
raise Kind::Error.new("expected #{self} to implement `#call`")
end
if public_methods.size > 1
raise Kind::Error.new("#{self} can only have `#call` as its public method")
end
if public_instance_method(:call).parameters.empty?
raise ArgumentError, "#{self.name}#call must receive at least one argument"
end
self.send(:include, Behavior)
def self.inherited(_)
raise RuntimeError, "#{self.name} is a Kind::Functional and it can't be inherited by anyone"
end
self.class_eval(
'def to_proc; @to_proc ||= method(:call).to_proc; end' \
"\n" \
'def curry; @curry ||= to_proc.curry; end'
)
__dependencies__.freeze
self
end
|