rails console 里的小技巧
app.class
=> ActionDispatch::Integration::Session
# 创建过程, 类似这样
new_app = Rails.application
session = ActionDispatch::Integration::Session.new(new_app)
session.class
=> ActionDispatch::Integration::Session其它
最后更新于
app.class
=> ActionDispatch::Integration::Session
# 创建过程, 类似这样
new_app = Rails.application
session = ActionDispatch::Integration::Session.new(new_app)
session.class
=> ActionDispatch::Integration::Session最后更新于
module UsersHelper
def user_help_1(user_name)
puts "I am June!"
end
def user_help_2
puts "I am June-Lee!"
end
end
# 原理类似
helper.send :extend, UsersHelper# 方法定义的地方
x.method(:method_name).source_location
# 方法内容
x.method(:method_name).source
# 方法前面的注释说明
x.method(:method_name).comment
# x 可以是对象、类、模块等# config/environments/test.rb
module Rails
module ConsoleMethods
def fg
@fg ||= FactoryGirl
end
end
end# config/application.rb
config.console do
require 'pry'
config.console = Pry
end