diff --git a/lib/dry/struct/class_interface.rb b/lib/dry/struct/class_interface.rb index 15f98fd..1806326 100644 --- a/lib/dry/struct/class_interface.rb +++ b/lib/dry/struct/class_interface.rb @@ -92,8 +92,8 @@ def inherited(klass) # ruby.celebrities[0].pseudonym #=> 'Matz' # ruby.celebrities[1].name #=> 'Aaron Patterson' # ruby.celebrities[1].pseudonym #=> 'tenderlove' - def attribute(name, type = Undefined, &block) - attributes(name => build_type(name, type, &block)) + def attribute(name, type = Undefined, &) + attributes(name => build_type(name, type, &)) end # Add atributes from another struct @@ -121,13 +121,13 @@ def attribute(name, type = Undefined, &block) # # @param struct [Dry::Struct] def attributes_from(struct) - extracted_schema = struct.schema.keys.map { |key| + extracted_schema = struct.schema.keys.to_h do |key| if key.required? [key.name, key.type] else [:"#{key.name}?", key.type] end - }.to_h + end attributes(extracted_schema) end @@ -148,7 +148,7 @@ def attributes_from(struct) def attribute?(*args, &block) if args.size == 1 && block.nil? Core::Deprecations.warn( - "Dry::Struct.attribute? is deprecated for checking attribute presence, "\ + "Dry::Struct.attribute? is deprecated for checking attribute presence, " \ "use has_attribute? instead", tag: :"dry-struct" ) @@ -246,7 +246,7 @@ def check_schema_duplication(new_keys) # @param [Hash{Symbol => Object},Dry::Struct] attributes # @raise [Struct::Error] if the given attributes don't conform {#schema} - def new(attributes = default_attributes, safe = false, &block) # rubocop:disable Style/OptionalBooleanParameter + def new(attributes = default_attributes, safe = false, &) # rubocop:disable Style/OptionalBooleanParameter if attributes.is_a?(Struct) if equal?(attributes.class) attributes @@ -256,7 +256,7 @@ def new(attributes = default_attributes, safe = false, &block) # rubocop:disable # User.new(super_user) # # We may deprecate this behavior in future forcing people to be explicit - new(attributes.to_h, safe, &block) + new(attributes.to_h, safe, &) end elsif safe load(schema.call_safe(attributes) { |output = attributes| return yield output }) @@ -268,11 +268,11 @@ def new(attributes = default_attributes, safe = false, &block) # rubocop:disable end # @api private - def call_safe(input, &block) + def call_safe(input, &) if input.is_a?(self) input else - new(input, true, &block) + new(input, true, &) end end diff --git a/lib/dry/struct/sum.rb b/lib/dry/struct/sum.rb index e683716..fd66ae6 100644 --- a/lib/dry/struct/sum.rb +++ b/lib/dry/struct/sum.rb @@ -28,7 +28,7 @@ def try(input) # @param [Dry::Types::Type] type # @return [Dry::Types::Sum] def |(type) - if type.is_a?(Class) && type <= Struct || type.is_a?(Sum) + if (type.is_a?(::Class) && type <= Struct) || type.is_a?(Sum) Sum.new(self, type) else super diff --git a/spec/integration/constructor_spec.rb b/spec/integration/constructor_spec.rb index a35f81d..fc4216b 100644 --- a/spec/integration/constructor_spec.rb +++ b/spec/integration/constructor_spec.rb @@ -27,7 +27,7 @@ describe "#prepend" do let(:type) do - super().prepend { |x| x.map { |k, v| [k.to_sym, v] }.to_h } + super().prepend { |x| x.to_h { |k, v| [k.to_sym, v] } } end specify do diff --git a/spec/integration/pattern_matching_spec.rb b/spec/integration/pattern_matching_spec.rb index a681d7e..9959792 100644 --- a/spec/integration/pattern_matching_spec.rb +++ b/spec/integration/pattern_matching_spec.rb @@ -51,8 +51,6 @@ def match(user) "Alice or Carol" in User(first_name:, last_name: "Doe") "DOE, #{first_name.upcase}" - in User(first_name:, last_name: "Doe") - "DOE, #{first_name.upcase}" in User(first_name:, address: Address(street: "Downing street")) "PM is #{first_name}" end @@ -76,6 +74,7 @@ def match(user) example "multiple structs" do case john in User(first_name: "John" | "Jack") + "John or Jack" end end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 23d3260..091769b 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -24,7 +24,7 @@ module DryStructSpec rescue LoadError end -Dir[Pathname(__dir__).join("shared/*.rb")].sort.each(&method(:require)) +Dir[Pathname(__dir__).join("shared/*.rb")].each(&method(:require)) require "dry/types/spec/types" RSpec.configure do |config|