Skip to content

Commit aaf5037

Browse files
committed
Syntax updates
1 parent 1e72b21 commit aaf5037

File tree

5 files changed

+21
-27
lines changed

5 files changed

+21
-27
lines changed

lib/dry/logic/operations/abstract.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ module Logic
55
module Operations
66
class Abstract
77
include Core::Constants
8-
include Dry::Equalizer(:rules, :options)
8+
include ::Dry::Equalizer(:rules, :options)
99
include Operators
1010

1111
attr_reader :rules

lib/dry/logic/operations/each.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def call(input)
2323
end
2424

2525
def [](arr)
26-
arr.map { |input| rule[input] }.all?
26+
arr.all? { |input| rule[input] }
2727
end
2828
end
2929
end

lib/dry/logic/result.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
module Dry
44
module Logic
55
class Result
6-
SUCCESS = Class.new {
6+
SUCCESS = ::Class.new {
77
def success?
88
true
99
end

lib/dry/logic/rule.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def self.Rule(*args, **options, &block)
1414

1515
class Rule
1616
include Core::Constants
17-
include Dry::Equalizer(:predicate, :options)
17+
include ::Dry::Equalizer(:predicate, :options)
1818
include Operators
1919

2020
attr_reader :predicate
@@ -32,7 +32,7 @@ def self.interfaces
3232
def self.specialize(arity, curried, base = Rule)
3333
base.interfaces.fetch_or_store([arity, curried]) do
3434
interface = Interface.new(arity, curried)
35-
klass = Class.new(base) { include interface }
35+
klass = ::Class.new(base) { include interface }
3636
base.const_set("#{base.name.split("::").last}#{interface.name}", klass)
3737
klass
3838
end

lib/dry/logic/rule/interface.rb

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,11 @@ def initialize(arity, curried)
2929
end
3030
end
3131

32-
def constant?
33-
arity.zero?
34-
end
32+
def constant? = arity.zero?
3533

36-
def variable_arity?
37-
arity.negative?
38-
end
34+
def variable_arity? = arity.negative?
3935

40-
def curried?
41-
!curried.zero?
42-
end
36+
def curried? = !curried.zero?
4337

4438
def unapplied
4539
if variable_arity?
@@ -116,26 +110,26 @@ def define_application
116110
application = "@predicate[#{(curried_args + unapplied_args + splat).join(", ")}]"
117111

118112
module_eval(<<~RUBY, __FILE__, __LINE__ + 1)
119-
def call(#{parameters}) # def call(input0, input1, *rest)
120-
if #{application} # if @predicate[@arg0, @arg1, input0, input1, *rest]
121-
Result::SUCCESS # ::Dry::Logic::Result::Success
122-
else # else
123-
Result.new(false, id) { ast(#{parameters}) } # ::Dry::Logic::Result.new(false, id) { ast(input0, input1, *rest) }
124-
end # end
125-
end # end
126-
#
127-
def [](#{parameters}) # def [](@arg0, @arg1, input0, input1, *rest)
128-
#{application} # @predicate[@arg0, @arg1, input0, input1, *rest]
129-
end # end
113+
def call(#{parameters}) # def call(input0, input1, *rest)
114+
if #{application} # if @predicate[@arg0, @arg1, input0, input1, *rest]
115+
Result::SUCCESS # ::Dry::Logic::Result::Success
116+
else # else
117+
Result.new(false, id) { ast(#{parameters}) } # ::Dry::Logic::Result.new(false, id) { ast(input0, input1, *rest) }
118+
end # end
119+
end # end
120+
#
121+
def [](#{parameters}) # def [](@arg0, @arg1, input0, input1, *rest)
122+
#{application} # @predicate[@arg0, @arg1, input0, input1, *rest]
123+
end # end
130124
RUBY
131125
end
132126

133127
def curried_args
134-
@curried_args ||= ::Array.new(curried) { |i| "@arg#{i}" }
128+
@curried_args ||= ::Array.new(curried) { "@arg#{_1}" }
135129
end
136130

137131
def unapplied_args
138-
@unapplied_args ||= ::Array.new(unapplied) { |i| "input#{i}" }
132+
@unapplied_args ||= ::Array.new(unapplied) { "input#{_1}" }
139133
end
140134
end
141135
end

0 commit comments

Comments
 (0)