Let's say I have a Virtus model User
with a boolean attribute active
:
class User
include Virtus.model
attribute :active, Boolean, default: false, lazy: true
end
Then I could user a helper method active?
:
User.new.active? # => false
User.new(active: true).active? # => true
But when I try to extend
from Virtus.model
and define a boolean attribute on the fly:
class User; end
user = User.new
user.extend(Virtus.model)
user.attribute(:active, Axiom::Types::Boolean, default: false, lazy: true)
user.active = true
and use a helper method active?
I get a NoMethodError
kinda exception.
user.active? # => NoMethodError: undefined method `active?' for
Is there any possibility of using helper methods in this situation?
user.active
is also giving error? I mean without?
– Emulsoiduser.active
works just fine. It is just that usingactive?
looks a lot more distinct in that way and doesn't differ from other boolean logic checks in the application. – Opponentundefined method
active?' for.....?` – EmulsoidNoMethodError: undefined method `active?' for #<User:0x007fb18fc59cc8>
) – Opponent