Accessing objects in a ruby struct. Can find the object but cannot call method on the struct
class ScrapeJob < Struct.new(:scrape_id)
def perform
@scrape = Scrape.find(scrape_id)
puts @scrape.link
end
end
Why can I find this object @scrape
but I cannot ask it for any of it's attributes in this struct
. @scrape.link
is just a string and console returns an error that I cannot call a private me开发者_如何学编程thod. How can I get this objects info?
I think you are forgetting to give your Struct a name, so scrape_id
becomes the name class name. The syntax you probably want to use is:
ScrapeJob = Struct.new(:scrape_id) do
...
end
精彩评论