Tag: 检查

什么是受污染的物体,什么时候应该解开它们?

什么时候Ruby对象需要被污染,什么时候应该解开它们? 受污染对象的概念如何使Ruby脚本以安全模式运行? 任何人都可以详细说明这一点,以便用一些代码片段清楚地理解这个概念吗?

为什么我用#inspect获得Encoding :: CompatibilityError?

以下代码没有问题: #encoding: utf-8 class Text def initialize(txt) @txt = txt end def inspect “” % @txt end end p Text.new(‘Hello World’) 但是,如果我尝试使用p Text.new(‘Hä, was soll das?’)我会得到一个Encoding :: CompatibilityError: inspect_with_umlaut.rb:26:in `p’: inspected result must be ASCII only or use the default external encoding (Encoding::CompatibilityError) from inspect_with_umlaut.rb:26:in `’ 为什么这个? 更重要的是:我该如何避免它?

如何解决`对象不支持#inspection`错误?

我正在使用rails v3.2.2,当我尝试加载相关记录时,我收到一个奇怪的错误。 以下是我得到的终端输入/输出: 1.9.2-p318 :011 > Category.first => # 1.9.2-p318 :013 > Category.first.articles Article Load (0.2ms) SELECT `articles`.* FROM `articles` LIMIT 1 (Object doesn’t support #inspect) 1.9.2-p318 :014 > Category.first.articles.first Category Load (0.2ms) SELECT `categories`.* FROM `categories` LIMIT 1 NoMethodError: undefined method `scoped’ for Category::Article:Module from //.rvm/gems/ruby-1.9.2-p318/gems/activerecord-3.2.2/lib/active_record/associations/association.rb:123:in `target_scope’ from //.rvm/gems/ruby-1.9.2-p318/gems/activerecord-3.2.2/lib/active_record/associations/through_association.rb:15:in `target_scope’ from //.rvm/gems/ruby-1.9.2-p318/gems/activerecord-3.2.2/lib/active_record/associations/association.rb:87:in `scoped’ from […]