the rails console tries to be smart, but isn't. if you want to know which public methods to call just do app.public_methods
Why rails console autocomplete feature shows methods that an object doesn't have? How to truncate them form defined ones?
-
30-05-2022 - |
题
For example, this is a rails console session. I use tab
key to get all available methods of app
. But many of them is not possible to call:
irb(main):040:0> app.default
app.default app.default_executable= app.default_locale app.default_scoped?
app.default= app.default_external_encoding app.default_locale= app.default_scopes
app.default_action app.default_external_encoding= app.default_lockfile app.default_scopes?
app.default_actions app.default_form_builder app.default_middleware_stack app.default_separator
app.default_adapter app.default_form_builder= app.default_options app.default_separator=
app.default_argv app.default_format app.default_options= app.default_sequence_name
app.default_argv= app.default_format= app.default_port app.default_timezone
app.default_asset_host_protocol app.default_format? app.default_proc app.default_uri
app.default_asset_host_protocol= app.default_formats app.default_proc= app.default_url_options
app.default_charset app.default_gem? app.default_regexp? app.default_url_options=
app.default_charset= app.default_gemfile app.default_render app.default_url_options?
app.default_dump_options app.default_handlers app.default_scope app.default_value
app.default_encoding app.default_host app.default_scope= app.defaults
app.default_engine app.default_inspect app.default_scoped
app.default_executable app.default_load_options app.default_scoped=
irb(main):043:0> app.default
NoMethodError: undefined method `default' for #ActionDispatch::Integration::Session:0x2e52208>
irb(main):042:0> app.default_lockfile
NoMethodError: undefined method `default_lockfile' for #ActionDispatch::Integration::Session:0x2e52208>
irb(main):041:0> app.default_locale
NoMethodError: undefined method `default_locale' for #ActionDispatch::Integration::Session:0x2e52208>
Console says the object has them, but if called they are suddenly undefined. Is this a bug? How to get only defined ones?
解决方案
不隶属于 StackOverflow