Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
369 views
in Technique[技术] by (71.8m points)

ruby on rails - Elastic gem. Why are the classes being compared incorrectly?

I use elasticsearch-model and elasticsearch-rails gems in my rails project. After searching, bunch of records are paginated and records method being called.

records = search_results.page(count).records

and when I got first record from records, for example, entity of Product class, and compare with class it returns false, but entity class is Product, why?

#returns Product entity

records.first

records.first.is_a?(Product)     #=> false
records.first.class == Product   #=> false
records.first.class.name         #=> "Product"

I can compare with class.name == "Product", but why classes don't compare correctly?

EDIT: method records returns the collection of records from the database


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...