Skip to content

Instantly share code, notes, and snippets.

@kml
Last active December 13, 2016 22:51
Show Gist options
  • Save kml/da4f7cf70008986b3ba5 to your computer and use it in GitHub Desktop.
Save kml/da4f7cf70008986b3ba5 to your computer and use it in GitHub Desktop.
Don't raise and rescue exception - just check
# encoding: utf-8
# Source: https://gist.github.com/kml/da4f7cf70008986b3ba5
# Issue: https://github.com/solnic/coercible/issues/16
require "virtus/attribute/coercer"
# Coercible::Coercer::Object#to_string doesn't know how to coerce nil
# https://github.com/solnic/virtus/blob/master/lib/virtus/attribute/coercer.rb#L31
module Virtus
class Attribute
class Coercer
alias virtus_call call
def call(value)
return if value.nil?
virtus_call(value)
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment