virtus
virtus copied to clipboard
Calling methods inside of a Virtus::Attribute
I have a Child class of Virtus::Attribute
called SortedComponents
Which looks like this:
class SortedComponents < Virtus::Attribute
def coerce(components)
components = (components).sort! { |a, b| a["description"] <=> b["description"] }
components = nest_components(components)
end
def self.nest_components(components)
components.delete_if do |c|
/[0-9]+[A-Z]+/ =~ c["description"] ? true : false
end
end
end
However, I'm not able to call "nest_components" in "coerce" and get the error:
app/models/SortedComponents.rb:4:in `coerce': undefined method `nest_components' for #<SortedComponents:0x007fcd132ea300> (NoMethodError)
How can I call methods from coerce in my Virtus::Attribute because not being able to break up some of the steps in coerce into seperate methods will make coerce huge?