Skip to content

Instantly share code, notes, and snippets.

@squarism
Last active December 10, 2015 01:38
Show Gist options
  • Save squarism/4360249 to your computer and use it in GitHub Desktop.
Save squarism/4360249 to your computer and use it in GitHub Desktop.
Why does this happen?
# 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