Tag: 别名方法

类`ActionView :: Base’的未定义方法`render’

当我启动应用程序崩溃后出现错误 /home/stereodenis/.rvm/gems/ruby-1.9.3-p194@nyanya/gems/haml-3.1.6/lib/haml/helpers/action_view_mods.rb:15:in `alias_method’: undefined method `render’ for class `ActionView::Base’ (NameError) 可能有什么不对? 完整跟踪https://gist.github.com/5e3244d488068c9d0ba7

alias_method和class_methods不混用?

我一直在尝试修补全局缓存模块,但我无法弄清楚为什么这不起作用。 有没有人有什么建议? 这是错误: NameError: undefined method `get’ for module `Cache’ from (irb):21:in `alias_method’ …由此代码生成: module Cache def self.get puts “original” end end module Cache def self.get_modified puts “New get” end end def peek_a_boo Cache.module_eval do # make :get_not_modified alias_method :get_not_modified, :get alias_method :get, :get_modified end Cache.get Cache.module_eval do alias_method :get, :get_not_modified end end # test […]

包含模块时__callee__的意外值 – 这是一个Ruby错误吗?

当通过alias_method创建的方法调用时, __callee__忽略旧方法的名称(此处为xxx )并返回新方法的名称,如下所示: class Foo def xxx() __callee__ end alias_method :foo, :xxx end Foo.new.foo # => :foo 即使从超类inheritancexxx此行为也成立: class Sup def xxx() __callee__ end end class Bar :bar 考虑到上述两种情况,我预计当通过模块包含xxx时,相同的行为将成立。 但事实并非如此: module Mod def xxx() __callee__ end end class Baz include Mod alias_method :baz, :xxx end Baz.new.baz # => :xxx 我希望返回值为:baz ,而不是:xxx 。 上面的代码是使用Ruby 2.3.1p112执行的。 这是__callee__实现中的__callee__吗? […]