Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Calling methods inside of a Virtus::Attribute #383

Open
bumble-bee-chuna opened this issue Aug 30, 2017 · 0 comments
Open

Calling methods inside of a Virtus::Attribute #383

bumble-bee-chuna opened this issue Aug 30, 2017 · 0 comments

Comments

@bumble-bee-chuna
Copy link

bumble-bee-chuna commented Aug 30, 2017

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant