virtus icon indicating copy to clipboard operation
virtus copied to clipboard

Calling methods inside of a Virtus::Attribute

Open bumble-bee-chuna opened this issue 7 years ago • 0 comments

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?

bumble-bee-chuna avatar Aug 30 '17 19:08 bumble-bee-chuna