Skip to content

Calling methods inside of a Virtus::Attribute  #383

@bumble-bee-chuna

Description

@bumble-bee-chuna

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions