Skip to content

custom coercion with arrays #284

Description

@doughsay

Using virtus 1.0.3 I get this behavior when attempting custom coercion with an array:

class MyInt < Virtus::Attribute
  def coerce(value)
    value.to_i
  end
end

class Thing
  include Virtus.model

  attribute :int, MyInt
  attribute :ints, Array[MyInt]
end

Thing.new(:int => '1', :ints => ['1', '2'])
#<Thing:0x007f9b309a74a0 @int=1, @ints=["1", "2"]>

According to the readme this seems like it should work...
As you can see, the "int" field was coerced but the "ints" array was not. Is this a bug or am I doing something wrong?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions