加密Gibberish nil:NilClass

时间:2014-11-09 14:47:30

标签: ruby encryption

我正在尝试使用以下类实现Gibberish加密:

class Encrypt
    def initialize()
        @cipher = Gibberish::AES.new("Kudzu")
    end
    def encode(caller)
        if((caller.is_a? Account) || (caller.is_a? Atm))
            return @cipher.enc("Kumquat")
        else
            return false
        end
    end

    def decode(caller, key)
        if((caller.is_a? Account) || (caller.is_a? Atm))
            return @cipher.dec(key)
        else
            return false
        end
    end
end

使用以下方式实例化:

$encrypt = Encrypt.new

使用以下方法调用我的Atm类:

@key = $encrypt.encode(self)

我收到的错误是:

undefined method `encode' for nil:NilClass (NoMethodError)

我是否有些事情不能理解我的胡言乱语或其他一些愚蠢的错误?

同样在我的帐户课程中:

@key = $encrypt.decode(self, $encrypt.encode(self))

1 个答案:

答案 0 :(得分:0)

$encrypt在您的Atm课程中以某种方式结束nil。没有看到所有代码就无法提供更多帮助。请记住Global Variables are Evil(在ruby中使用$ variable)并尝试重新编写代码,这样您就不需要它们了。

相关问题