Skip to content

Commit 95e3395

Browse files
committed
Update syntax
1 parent 580b6e2 commit 95e3395

File tree

7 files changed

+20
-53
lines changed

7 files changed

+20
-53
lines changed

lib/dry/struct.rb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -221,9 +221,7 @@ def inspect
221221
# Pattern matching support
222222
#
223223
# @api private
224-
def deconstruct_keys(_keys)
225-
attributes
226-
end
224+
def deconstruct_keys(_keys) = attributes
227225
end
228226
end
229227

lib/dry/struct/class_interface.rb

Lines changed: 10 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -313,48 +313,32 @@ def try_struct(input)
313313

314314
# @param [({Symbol => Object})] args
315315
# @return [Dry::Types::Result::Success]
316-
def success(*args)
317-
result(Types::Result::Success, *args)
318-
end
316+
def success(*args) = result(Types::Result::Success, *args)
319317

320318
# @param [({Symbol => Object})] args
321319
# @return [Dry::Types::Result::Failure]
322-
def failure(*args)
323-
result(Types::Result::Failure, *args)
324-
end
320+
def failure(*args) = result(Types::Result::Failure, *args)
325321

326322
# @param [Class] klass
327323
# @param [({Symbol => Object})] args
328-
def result(klass, *args)
329-
klass.new(*args)
330-
end
324+
def result(klass, *args) = klass.new(*args)
331325

332326
# @return [false]
333-
def default?
334-
false
335-
end
327+
def default? = false
336328

337329
# @param [Object, Dry::Struct] other
338330
# @return [Boolean]
339-
def ===(other)
340-
other.is_a?(self)
341-
end
331+
def ===(other) = other.is_a?(self)
342332
alias_method :primitive?, :===
343333

344334
# @return [true]
345-
def constrained?
346-
true
347-
end
335+
def constrained? = true
348336

349337
# @return [self]
350-
def primitive
351-
self
352-
end
338+
def primitive = self
353339

354340
# @return [false]
355-
def optional?
356-
false
357-
end
341+
def optional? = false
358342

359343
# @return [Proc]
360344
def to_proc
@@ -365,9 +349,7 @@ def to_proc
365349
#
366350
# @param [Symbol] key Attribute name
367351
# @return [Boolean]
368-
def has_attribute?(key)
369-
schema.key?(key)
370-
end
352+
def has_attribute?(key) = schema.key?(key)
371353

372354
# Gets the list of attribute names
373355
#
@@ -483,10 +465,7 @@ def #{key} # def email
483465
private :define_accessors
484466

485467
# @api private
486-
def valid_method_name?(key)
487-
key.to_s.match?(/\A[a-zA-Z_]\w*\z/)
488-
end
489-
private :valid_method_name?
468+
private def valid_method_name?(key) = key.to_s.match?(/\A[a-zA-Z_]\w*\z/)
490469
end
491470
end
492471
end

lib/dry/struct/extensions/pretty_print.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# frozen_string_literal: true
22

3-
require "pp" # rubocop:disable Lint/RedundantRequireStatement
3+
require "pp"
44

55
module Dry
66
class Struct

lib/dry/struct/hashify.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ module Hashify
99
# @return [Hash, Array]
1010
def self.[](value)
1111
if value.is_a?(Struct)
12-
value.to_h.transform_values { |current| self[current] }
12+
value.to_h.transform_values { self[_1] }
1313
elsif value.respond_to?(:to_hash)
14-
value.to_hash.transform_values { |current| self[current] }
14+
value.to_hash.transform_values { self[_1] }
1515
elsif value.respond_to?(:to_ary)
16-
value.to_ary.map { |item| self[item] }
16+
value.to_ary.map { self[_1] }
1717
else
1818
value
1919
end

lib/dry/struct/struct_builder.rb

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,17 +43,13 @@ def call(attr_name, type, &)
4343

4444
private
4545

46-
def type?(type)
47-
type.is_a?(Types::Type)
48-
end
46+
def type?(type) = type.is_a?(Types::Type)
4947

5048
def array?(type)
5149
type?(type) && !type.optional? && type.primitive.equal?(::Array)
5250
end
5351

54-
def optional?(type)
55-
type?(type) && type.optional?
56-
end
52+
def optional?(type) = type?(type) && type.optional?
5753

5854
def parent(type)
5955
if array?(type)
@@ -95,9 +91,7 @@ def visit_array(node)
9591
visit(member)
9692
end
9793

98-
def visit_nominal(*)
99-
Undefined
100-
end
94+
def visit_nominal(*) = Undefined
10195

10296
def visit_constructor(node)
10397
definition, * = node

lib/dry/struct/sum.rb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,7 @@ def |(type)
3636
end
3737

3838
# @return [boolean]
39-
def ===(value)
40-
left === value || right === value
41-
end
39+
def ===(value) = left === value || right === value
4240

4341
protected
4442

lib/dry/struct/value.rb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,7 @@ class Value < self
2929
# @param (see ClassInterface#new)
3030
# @return [Value]
3131
# @see https://github.com/dkubb/ice_nine
32-
def self.new(*)
33-
::IceNine.deep_freeze(super)
34-
end
32+
def self.new(*) = ::IceNine.deep_freeze(super)
3533
end
3634

3735
deprecate_constant :Value

0 commit comments

Comments
 (0)