Last active
December 10, 2015 01:38
-
-
Save squarism/4360249 to your computer and use it in GitHub Desktop.
Why does this happen?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# In some situations, methods on objects in irb and pry really aren't there. | |
# Fire up a rails app in pry. Actually, in my case this was a CLI app. | |
# It happens in pry and irb. In rails and outside of rails. | |
# I think the key is the where statement. | |
>> rows = User.where('email is not null') | |
# hit [tab] [tab] after typing 'path' as an example | |
>> rows.first.path | |
rows.first.path rows.first.path= rows.first.path_fingerprint | |
rows.first.path_for_action rows.first.path_info rows.first.path_info= | |
rows.first.path_parameters rows.first.path_parameters= rows.first.path_to_audio | |
rows.first.path_to_image rows.first.path_to_javascript rows.first.path_to_stylesheet | |
rows.first.path_to_video rows.first.path_translated rows.first.path_with_fingerprint | |
rows.first.pathname rows.first.paths rows.first.paths_contain? | |
# See? It has a method called path. Wtf is a database row path? Who knows? Let's call it! | |
rows.first.path | |
=> NoMethodError: undefined method 'path' for #<User: ...> | |
# What. | |
# But Ruby knows it isn't there when we look for it in public_methods | |
[25] pry(main)> rows.first.public_methods.select {|m| m.to_s.match /^path/ } | |
=> [] | |
# So I guess it's pry or irb. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment